
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
- Image Loading issue in Snapgram project
Hello community, I have a issue with the Image Loading I made a Project from youtube of Snapgram, it worked perfectly 8 months ago, but now the images aren't l...
- Incorrect MIME type in storage.createFil...
I’m facing an issue with storage.createFile. I’m trying to upload a .css file and I’ve explicitly set the MIME type to "text/css" when creating the file. But a...
- How to run queries to get the storage li...
I installed the n8n (self-hosting) and community node n8n-nodes-nappwrite. I tried to get the storage list files more than 25 records. But I cannot find the w...
