storageAsyncResult.End(); throws NullReferenceException.. most times.
See original GitHub issueRunning the following code some images work to upload and others don’t. I have tried to figure out what differs them but an image that works to upload can later fail and vice versa.
This is the code I use to upload blobs:
public async Task UploadAndSaveBlobAsync(string adId, IFormFile imageFile, string fileName){
var blobName = adId + "/" + fileName;
await _container.CreateIfNotExistsAsync();
await _container.SetPermissionsAsync(new BlobContainerPermissions
{
PublicAccess = BlobContainerPublicAccessType.Blob
});
var blockBlob = _container.GetBlockBlobReference(blobName);
blockBlob.Properties.ContentType = imageFile.ContentType;
try
{
using (var stream = imageFile.OpenReadStream())
{
await blockBlob.UploadFromStreamAsync(stream);
}
}
catch (Exception e)
{
Trace.TraceError("Could not upload image" + e.Message);
throw;
}
var blobsName = blockBlob.Uri.ToString();
}
/End example code
And here is the StackTrace for "“Object reference not set to an instance of an object.”
" at Microsoft.WindowsAzure.Storage.Core.Util.StorageAsyncResult`1.End() in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Util\StorageAsyncResult.cs:line 77\r\n at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.EndUploadFromStream(IAsyncResult asyncResult) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Blob\CloudBlockBlob.cs:line 739\r\n at Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions.<>c__DisplayClass4.<CreateCallbackVoid>b__3(IAsyncResult ar) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Util\AsyncExtensions.cs:line 114\r\n— End of stack trace from previous location where exception was thrown —\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n at Mulimo.DAL.BlobStorage.<UploadAndSaveBlobAsync>d__7.MoveNext() in C:\Source\Mulimo\src\Mulimo.DAL\BlobStorage.cs:line 70"
Issue Analytics
- State:
- Created 8 years ago
- Comments:34 (12 by maintainers)
Top GitHub Comments
I’m not sure if this is expected to work too (considering https://github.com/aspnet/HttpAbstractions/issues/602) but it seems to be an alternative solution using streams.
I’m not expecting any evident improvement over using UploadFromByteArrayAsync, obviously.
I can reproduce this problem every time when I use mono and want to use the Azure Storage on both Windows and Ubuntu 14.04 (didn’t test Mac OS X). The problem exists since (at least 3.2.1). I didn’t test older versions.
EDIT: Added stack trace EDIT 2: Using
UploadFromByteArray
instead ofUploadFromByteArrayAsync
works. It seems that - when I use the*Async
methods, that a timeout is triggered (after ~30 seconds) that causes the NRE when the request ends.