Skip to content
This repository was archived by the owner on Aug 1, 2024. It is now read-only.
This repository was archived by the owner on Aug 1, 2024. It is now read-only.

storageAsyncResult.End(); throws NullReferenceException.. most times. #202

@mkarlsson

Description

@mkarlsson

Running 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.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.d__7.MoveNext() in C:\Source\Mulimo\src\Mulimo.DAL\BlobStorage.cs:line 70"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions