I hope you’re doing well. I’m encountering a NullReferenceException: Object reference not set to an instance of an object. whenever I call storage.CreateFile(...) in the .NET C# SDK. I’ve spent a lot of time debugging and I can’t pinpoint whether this is a mistake in my code or an SDK issue.
Below is a minimal summary of my environment and reproduction steps:
// 1) I fetch the existing user document to read the old avatar ID
var doc = await databases.GetDocument(dbId, logopedistCollectionId, user.Id);
var oldAvatarId = doc.Data["avatarId"] as string;
// 2) I decide I need to replace the image
// – so I delete the old file if it exists
if (!string.IsNullOrEmpty(oldAvatarId))
await storage.DeleteFile(bucketId, oldAvatarId);
// 3) I prepare the new image
var imageBytes = Convert.FromBase64String(updateModel.Photo.Data);
var inputFile = InputFile.FromBytes(imageBytes, updateModel.Photo.Name, mimeType);
// 4) **This line throws a NullReferenceException internally in the SDK**:
await storage.CreateFile(bucketId, newFileId, inputFile);
🔍 What I’ve Checked Bucket ID ‑ Verified that bucketId is the correct Storage bucket (not the database ID).
InputFile ‑ Confirmed imageBytes is non‑null/empty. ‑ inputFile.Name and inputFile.MimeType are both non‑null, non‑empty strings.
Permissions ‑ Confirmed my service API key has full read/write access to the bucket.
Alternative Workarounds ‑ Tried uploading via JavaScript SDK to the same bucket with an identical file → works fine. ‑ Tested uploading a small “hello world” text file via C# → succeeds.
So the only failing scenario is uploading a binary image via InputFile.FromBytes(…, “avatar.png”, “image/png”).
Do you have the full stack trace you can provide?
Recommended threads
- Websites hosted on my appwrite sites hav...
Hello, all my websites hosted on appwrite sites are not running I am getting this message "This site can’t be reached drivehub.appwrite.network took too long t...
- Can't really use the S3 storage device
hi, I've linked my local MinIO Instance (it's just for testing, not for prod.) to my appwrite instance, when i'm uploading a file it's getting uploaded to the S...
- Storage Chunk upload bug
Hi, I'm experiencing an issue with Appwrite Storage chunked uploads. Small files upload successfully, but larger video files that require chunking fail. For ...