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
- I am using s3 for app storage but is it ...
_APP_STORAGE_DEVICE=s3 puts everything to the s3 storage but i need to be able to keep the function builds and site in the local and not waste the cloud storage...
- All My Project is Gone
Hello everyone, please help. Why have all my projects suddenly disappeared? I received a warning via email about one of my projects being paused. When I clicked...
- Appwrite for Education
I am writing to report an issue with my account limits. I currently have the GitHub Student Developer Pack active, which should include 10 Appwrite Pro projects...