React Developer
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 IDvar 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 existsif (!string.IsNullOrEmpty(oldAvatarId)) await storage.DeleteFile(bucketId, oldAvatarId);
// 3) I prepare the new imagevar 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”).