New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mkarlsson opened this Issue Nov 22, 2015 · 34 comments

Comments

Projects
None yet
@mkarlsson

mkarlsson commented Nov 22, 2015

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"

@pemari-msft

This comment has been minimized.

Contributor

pemari-msft commented Nov 22, 2015

Hi, can you clarify what platform you're targeting? Can you give us some information to help us try to repro (I wasn't able to myself).

Thanks!

@mkarlsson

This comment has been minimized.

mkarlsson commented Nov 23, 2015

Hi, here is the project.json from my DAL lib.
{
"version": "1.0.0-*",
"description": "Mulimo.DAL Class Library",
"authors": [ "Magnus" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"dependencies": {
"Mulimo.Domain": "",
"Mulimo.DALInterfaces": "",
"WindowsAzure.Storage": "6.1.0",
"Microsoft.AspNet.Hosting.Abstractions": "1.0.0-rc1-final",
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc1-final",
"Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0-rc1-final"
},
"frameworks": {
"net451": { }
}
}

@mkarlsson

This comment has been minimized.

mkarlsson commented Nov 23, 2015

Here is the BlobStorage file

public class BlobStorage : IBlobStorage
    {
        CloudBlobClient _blobClient;
        CloudBlobContainer _container;
        public IConfigurationRoot Configuration { get; set; }

        public BlobStorage(IHostingEnvironment env, IApplicationEnvironment appEnv)
        {
            var builder = new ConfigurationBuilder()
                .AddJsonFile("appsettings.json")
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);


            builder.AddEnvironmentVariables();
            Configuration = builder.Build();

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
  Configuration["MicrosoftAzureStorage:fake_AzureStorageConnectionString"]);

            // Create a blob client.
            _blobClient = storageAccount.CreateCloudBlobClient();
            _blobClient.DefaultRequestOptions.RetryPolicy = new LinearRetry(TimeSpan.FromSeconds(3), 3);

            _container = _blobClient.GetContainerReference("images");

            _container.CreateIfNotExistsAsync();
        }

        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
            });
            //Get reference to a 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();

        }

        static byte[] GetBytes(string str)
        {
            byte[] bytes = new byte[str.Length * sizeof(char)];
            System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
            return bytes;
        }

        public async Task<bool> AddToBlob(string folder, string name)
        {

            // Get a reference to a blob named "myblob".
            CloudBlockBlob blockBlob = _container.GetBlockBlobReference("myblob");

            // Create or overwrite the "myblob" blob with the contents of a local file
            // named “myfile”.
            using (var fileStream = File.OpenRead(@"path\myfile"))
            {
                await blockBlob.UploadFromStreamAsync(fileStream);
            }
            return true;
        }

    }
@mkarlsson

This comment has been minimized.

mkarlsson commented Nov 23, 2015

Current situation is the following image work
https://dl.dropboxusercontent.com/u/1052402/storageerror/WIN_20151118_13_39_14_Pro.jpg
(This is a picture from my camera roll of Ryan @msft)
and this one does not.
https://dl.dropboxusercontent.com/u/1052402/storageerror/bild3.jpg
(random picture of Volvo S60 )

@pemari-msft

This comment has been minimized.

Contributor

pemari-msft commented Nov 23, 2015

Hi @mkarlsson , it seems from your project.json file that you're taking a dependency on our GA library (which doesn't support DNX 4.5.1 or DNX Core 5.0) and that you're looking to use it on the DNX 4.5.1 or DNX Core 5.0 1.0.0-rc1 bits. Can you confirm this?

If so, please take a look at our readme, and especially the Versioning Info Section.

If you want to use our CoreCLR/DNX4.5.1 library, please take a look at our 6.1.1-preview package and please note that we currently support up to beta8 and are working to update to rc1 soon.

Thanks!

@mkarlsson

This comment has been minimized.

mkarlsson commented Nov 23, 2015

Yes, I'm targeting dnx 4.5.1. so I'm really looking forward to the upcoming rc1 release now. You think you'll get it out this week, next week, or next month?

You can go ahead and close this issue btw.

Cheers!

@mkarlsson mkarlsson closed this Nov 26, 2015

@mkarlsson mkarlsson reopened this Dec 12, 2015

@mkarlsson

This comment has been minimized.

mkarlsson commented Dec 12, 2015

I just installed "WindowsAzure.Storage": "6.2.2-preview", and get the same error as earlier. I have a brand new setup(SPRO4) with VS2015 Enterprise and the latest piece of DNX. I don't target core54.

In my comment 19 days ago I found I can post one image but not the other. That example is true even now.

This is the stacktrace error from my catch clause.

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
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
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
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Mulimo.DAL.BlobStorage.d__7.MoveNext() in C:\Source\Mulimo\src\Mulimo.DAL\BlobStorage.cs:line 70

@mkarlsson

This comment has been minimized.

mkarlsson commented Dec 17, 2015

ping

@pemari-msft

This comment has been minimized.

Contributor

pemari-msft commented Dec 17, 2015

Hi @mkarlsson,

I'm still not able to repro the issue. If you're targeting DNX and not Core, the dll has actually changed from 6.1.1-preview to 6.2.2-preview so it's not even the same code running anymore. The 'upload a blob' case is one of our most basic tests, so this must definitely be a particular scenario that's failing. You say you can upload one image but not another? What's the difference between them? Can you provide us a small repro app?

@zapthedingbat

This comment has been minimized.

zapthedingbat commented Dec 17, 2015

I am seeing this exception intermittently. I'm using WindowsAzure.Storage 6.1.1-preview

NullReferenceException: Object reference not set to an instance of an object.
Microsoft.WindowsAzure.Storage.Core.Util.StorageAsyncResult`1.End() in StorageAsyncResult.cs, line 75


NullReferenceException: Object reference not set to an instance of an object.
Microsoft.WindowsAzure.Storage.Core.Util.StorageAsyncResult`1.End() in StorageAsyncResult.cs
Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.EndUploadFromStream(IAsyncResult asyncResult) in CloudBlockBlob.cs
Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions.<>c__DisplayClass4.<CreateCallbackVoid>b__3(IAsyncResult ar) in AsyncExtensions.cs
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
RadicalResearch.Narrator.Website.Controllers.AudioController.<Post>d__2.MoveNext() in AudioController.cs
                blobName = string.Concat(audioPost.Word.ToUpperInvariant(), ".", index);
                blockBlob = container.GetBlockBlobReference(blobName);
            }
            using (var stream = audioPost.File.OpenReadStream())
            {
                await blockBlob.UploadFromStreamAsync(stream);
            }
            // Add transcode message to queue
            var queueClient = storageAccount.CreateCloudQueueClient();
            var queue = queueClient.GetQueueReference("audio-transcode");
            await queue.AddMessageAsync(new CloudQueueMessage(blobName));
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNet.Mvc.Controllers.ControllerActionExecutor.<CastToObject>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
Microsoft.AspNet.Mvc.Controllers.ControllerActionInvoker.<InvokeActionAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.<InvokeActionFilterAsync>d__53.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.<InvokeAsync>d__44.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNet.Mvc.Infrastructure.MvcRouteHandler.<RouteAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNet.Mvc.Routing.InnerAttributeRoute.<RouteAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNet.Routing.RouteCollection.<RouteAsync>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNet.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNet.IISPlatformHandler.IISPlatformHandlerMiddleware.<Invoke>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNet.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()

Show raw exception details
No QueryString data.

No cookie data.

Variable    Value
Accept  */*
Accept-Encoding gzip, deflate
Accept-Language en-GB,en;q=0.8,en-US;q=0.6
Connection  Keep-Alive
Content-Length  94480
Content-Type    multipart/form-data; boundary=----WebKitFormBoundaryku1o4URnk5FPgGBH
DNT 1
Host    localhost:5000
Origin  http://localhost:5000
Referer http://localhost:5000/
User-Agent  Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
X-Forwarded-For [::1]:10597
X-Forwarded-Proto   http
X-Original-Proto    http

Github repo with code is available:

https://github.com/RadicalResearch/narrator/blob/master/RadicalResearch.Narrator.Website/Controllers/AudioController.cs#L48

The error is reproducible here https://narrator.radicalresearch.co.uk/ (although you will have to record a sound and monitor the response of the AJAX post)

@pemari-msft

This comment has been minimized.

Contributor

pemari-msft commented Dec 17, 2015

Interesting. And does it repro on 6.2.2-preview? I am unable to repro it myself and we have tests that we run before each release that upload hundreds if not thousands of blobs. Are you able to repro the behavior in a small sample console app separately from your larger codebase?

@zapthedingbat

This comment has been minimized.

zapthedingbat commented Dec 17, 2015

The same issue manifests in 6.2.2-preview.

I can't reproduce it in a Console app, but the exception is being thrown in an ASP.NET controller, perhaps its specific to the synchronization context being used?

@duanjian

This comment has been minimized.

duanjian commented Dec 18, 2015

@endink

This comment has been minimized.

endink commented Dec 18, 2015

@pemari-msft
i have the same issue, maybe because of the stream from IFormFile , property value of CanSeek always returned true , but it cant seek, this property being used by code of Azure storage?

@pemari-msft

This comment has been minimized.

Contributor

pemari-msft commented Dec 18, 2015

Thanks for reporting this. It sounds like there's some sort of interaction between us and ASP.NET. We'll take a closer look and try to determine what's happening by trying to repro in the ASP.NET controller. Please let us know if anyone finds any further information about this, otherwise, we'll provide an update when we find out what's occurring.

@endink

This comment has been minimized.

endink commented Dec 19, 2015

@pemari-msft
My problem is that exception occured when you upload a html file and exception does not occured when you upload a image file. the code line of the problem is:

Microsoft.WindowsAzure.Storage.Core.Util.StorageAsyncResult`1.End()
@mkarlsson

This comment has been minimized.

mkarlsson commented Dec 20, 2015

@pemari-msft

This comment has been minimized.

Contributor

pemari-msft commented Dec 21, 2015

Thanks @mkarlsson! I'll try to take a closer look soon.

@gongdo

This comment has been minimized.

gongdo commented Dec 23, 2015

I have same issue on it.
I was able to get work-around by using UploadFromByteArrayAsync instead.

@mkarlsson

This comment has been minimized.

mkarlsson commented Dec 23, 2015

Tried suggestion by @gongdo , like this and it works.
byte[] fileBytes = new byte[stream.Length];
await blockBlob.UploadFromByteArrayAsync(fileBytes, 0, fileBytes.Length);

@novogeek

This comment has been minimized.

novogeek commented Jan 20, 2016

I am facing the same issue while asynchronously uploading a stream from IFormFile to a block blob. I'm using "Microsoft.AspNet.Mvc": "6.0.0-rc1-final" and "WindowsAzure.Storage": "6.2.2-preview"

public async Task<IActionResult> SaveToAzureBlob(IFormFile file)
        {
            try
            {
                var filename = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_azureStorageConnStr);
                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
                CloudBlobContainer blobContainer = blobClient.GetContainerReference("azuresamples1337");
                await blobContainer.CreateIfNotExistsAsync();

                CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(filename);
                using (var fileStream = file.OpenReadStream())
                {
                    await blockBlob.UploadFromStreamAsync(fileStream);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return RedirectToAction("Index", "FileUpload");
        }

As suggested by others, using UploadFromByteArrayAsync works though. Let me know if you need repro sample.

@nporaMep

This comment has been minimized.

nporaMep commented Feb 10, 2016

I have same issue too when using IFormFile.OpenReadStream and passing that stream to CloudBlockBlob.UploadFromStreamAsync(). Issue happens on random file names, for example:
VALID NAMES:
admin_edit_page_021016.png
admin_page_021016.png
app_settings_021016.png
backlog_020116.png
backlog_020416.png
backlog_021016.png
backlogitems_020416.png
blog_020116.png
features_020116.png

WRONG NAMES:
test.png
TypeScript_Transpile_VS2015.1.png
npm_path_vs2015_1.png

They are all same PNGs created by OneNote Win+S and saved in Paint.

No issues if I read that stream to byte[] array and use CloudBlockBlob.UploadFromByteArrayAsync.

@emparker

This comment has been minimized.

emparker commented Feb 17, 2016

I am having same issue as well. It was working the whole day and out of the sudden, doesn't work now. Using UploadFromByteArrayAsync fix the problem.

@fubar-coder

This comment has been minimized.

fubar-coder commented Mar 21, 2016

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.

Microsoft.WindowsAzure.Storage.StorageException: Object reference not set to an instance of an object ---> System.NullReferenceException: Object reference not set to an instance of an object
  at System.Net.WebConnectionStream.EndRead (IAsyncResult r) <0xb804200 + 0x00061> in <filename unknown>:0
  at Microsoft.WindowsAzure.Storage.Core.ByteCountingStream.EndRead (IAsyncResult asyncResult) <0xb82e858 + 0x0001a> in <filename unknown>:0
  at Microsoft.WindowsAzure.Storage.Core.Util.AsyncStreamCopier`1[T].ProcessEndRead () <0xb836b70 + 0x0002d> in <filename unknown>:0
  at Microsoft.WindowsAzure.Storage.Core.Util.AsyncStreamCopier`1[T].EndOperation (IAsyncResult res) <0xb835fd8 + 0x00053> in <filename unknown>:0
  at Microsoft.WindowsAzure.Storage.Core.Util.AsyncStreamCopier`1[T].EndOpWithCatch (IAsyncResult res) <0xb835d30 + 0x00063> in <filename unknown>:0
  --- End of inner exception stack trace ---
  at Microsoft.WindowsAzure.Storage.Core.Util.StorageAsyncResult`1[T].End () <0xb84df40 + 0x0003f> in <filename unknown>:0
  at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.EndUploadFromStream (IAsyncResult asyncResult) <0xb84def8 + 0x0002f> in <filename unknown>:0
  at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.EndUploadFromByteArray (IAsyncResult asyncResult) <0xb84ded0 + 0x00017> in <filename unknown>:0
  at Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions+<>c__DisplayClass4.<CreateCallbackVoid>b__3 (IAsyncResult ar) <0xb84dc98 + 0x00095> in <filename unknown>:0

EDIT: Added stack trace
EDIT 2: Using UploadFromByteArray instead of UploadFromByteArrayAsync 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.

@davidfowl

This comment has been minimized.

davidfowl commented Mar 31, 2016

I investigate this issue and have found the cause of the bug aspnet/HttpAbstractions#602.

@davidfowl

This comment has been minimized.

davidfowl commented Mar 31, 2016

This should also be fixed in the Azure storage SDK.

@davidfowl

This comment has been minimized.

davidfowl commented Mar 31, 2016

The code here should be flowing the IAsyncResult through the call to ProcessEndRead()

and

@davidfowl

This comment has been minimized.

davidfowl commented Mar 31, 2016

Made a gist with some repro code https://gist.github.com/davidfowl/8cecb0a679576917cc169ddea65a3c29. You just need to provide a connection string and use any azure storage SDK version.

@bragma

This comment has been minimized.

bragma commented Apr 8, 2016

I'm not sure if this is expected to work too (considering aspnet/HttpAbstractions#602) but it seems to be an alternative solution using streams.

using (var imageStream = image.OpenReadStream())
{
    using (var memStream = new MemoryStream((int)image.Length))
    {
        await imageStream.CopyToAsync(memStream);
        memStream.Position = 0;
        await blockBlob.UploadFromStreamAsync(memStream);
    }
}

I'm not expecting any evident improvement over using UploadFromByteArrayAsync, obviously.

@davidfowl

This comment has been minimized.

davidfowl commented Apr 10, 2016

Yep that's a workaround. The only thing to look out for is buffering all of that data in memory...

@pbedat

This comment has been minimized.

pbedat commented Apr 14, 2016

I also came across the "StorageException: Object reference not set" error. But I'm not quite sure, wether this also blongs to aspnet/HttpAbstractions#602, because the mentioned workarounds dont work for me.

Here is the whole Dump of the Exception:

    Microsoft.WindowsAzure.Storage.StorageException: Object reference not set to an instance of an object
    ---> System.NullReferenceException: Object reference not set to an instance of an object
      at System.Net.WebConnectionStream.EndRead (IAsyncResult r) <0x41fc7860 + 0x0009e> in <filename unknown>:0 
      at Microsoft.WindowsAzure.Storage.Core.ByteCountingStream.EndRead (IAsyncResult asyncResult) <0x41fbc1c0 + 0x00024> in <filename unknown>:0 
      at Microsoft.WindowsAzure.Storage.Core.Util.AsyncStreamCopier`1[T].ProcessEndRead () <0x41fd7f10 + 0x0003b> in <filename unknown>:0 
      at Microsoft.WindowsAzure.Storage.Core.Util.AsyncStreamCopier`1[T].EndOperation (IAsyncResult res) <0x41fd71c0 + 0x00067> in <filename unknown>:0 
      at Microsoft.WindowsAzure.Storage.Core.Util.AsyncStreamCopier`1[T].EndOpWithCatch (IAsyncResult res) <0x41fd6e80 + 0x00073> in <filename unknown>:0 
      --- End of inner exception stack trace ---
      at Microsoft.WindowsAzure.Storage.Blob.BlobWriteStream.Flush () <0x41fdd180 + 0x0007b> in <filename unknown>:0 
      at Microsoft.WindowsAzure.Storage.Blob.BlobWriteStream.Commit () <0x41fdcf40 + 0x00023> in <filename unknown>:0 
      at Microsoft.WindowsAzure.Storage.Blob.BlobWriteStream.Dispose (Boolean disposing) <0x41fdced0 + 0x00043> in <filename unknown>:0 
      at System.IO.Stream.Close () <0x7f1e247c53d0 + 0x00019> in <filename unknown>:0 
      at System.IO.Stream.Dispose () <0x7f1e247c5400 + 0x00013> in <filename unknown>:0 
      at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromStreamHelper (System.IO.Stream source, Nullable`1 length, Microsoft.WindowsAzure.Storage.AccessCondition accessCondition, Microsoft.WindowsAzure.Storage.Blob.BlobRequestOptions options, Microsoft.WindowsAzure.Storage.OperationContext operationContext) <0x41fc9e10 + 0x009e0> in <filename unknown>:0 
      at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromStream (System.IO.Stream source, Microsoft.WindowsAzure.Storage.AccessCondition accessCondition, Microsoft.WindowsAzure.Storage.Blob.BlobRequestOptions options, Microsoft.WindowsAzure.Storage.OperationContext operationContext) <0x41fc9db0 + 0x0004b> in <filename unknown>:0 
      at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromFile (System.String path, Microsoft.WindowsAzure.Storage.AccessCondition accessCondition, Microsoft.WindowsAzure.Storage.Blob.BlobRequestOptions options, Microsoft.WindowsAzure.Storage.OperationContext operationContext) <0x41fc9cc0 + 0x00097> in <filename unknown>:0 
      at windowsstoragebug.MainClass.Main (System.String[] args) <0x41f1cd60 + 0x004f0> in <filename unknown>:0 
    Request Information
    RequestID:c4dedc47-0001-0038-734d-962acc000000
    RequestDate:Thu, 14 Apr 2016 12:56:26 GMT
    StatusMessage:Created

This one occurs with all the UploadFromX methods. When I try to use PutBlock instead, I receive even stranger behaviour. Either the application hangs, gives me a 400, works and/or spams those lines:

    _wapi_handle_ref: Attempting to ref unused handle 0x4af
    _wapi_handle_unref_full: Attempting to unref unused handle 0x4af

Here is a repo with the code to reproduce the errors with both methods: https://github.com/pbedat/azure-mono-bug
It can be executed with
docker run pbedat/azure-mono-bug <account-name> <account-key>

I've used version 7.0.0 with mono Stable 4.2.3.4 on Ubuntu 14.04. (See Dockerfile)

I hope this info might help a little!

BTW: I solved the issue for me by replacing the blob.PutBlock call with my own implementation of the REST api call.

@FabienLavocat

This comment has been minimized.

FabienLavocat commented May 8, 2016

I have the exact same problem with the versions:
"WindowsAzure.Storage": "7.0.1-preview"
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final"

The code from @bragma seems to work for me. Thanks.

skofman1 added a commit to NuGet/NuGet.Staging that referenced this issue May 13, 2016

@pemari-msft

This comment has been minimized.

Contributor

pemari-msft commented Oct 10, 2016

@luminescent

This comment has been minimized.

luminescent commented Nov 27, 2016

If it's of any help, the issue still persists on Mono with this version:

   <package id="WindowsAzure.Storage" version="7.2.1" targetFramework="net452" />

Running the same code on Windows works fine. Using the non-async versions of the methods works on both Windows and Ubuntu.
Please see below the stack trace from Mono:

Failed to upload file:///tools/small.csv because of Microsoft.WindowsAzure.Storage.StorageException: Object reference not set to an instance of an object ---> System.NullReferenceException: Object reference not set to an instance of an object
  at System.Net.WebConnectionStream.EndRead (IAsyncResult r) <0x403a4490 + 0x0009e> in <filename unknown>:0
  at Microsoft.WindowsAzure.Storage.Core.ByteCountingStream.EndRead (IAsyncResult asyncResult) <0x4038d910 + 0x00024> in <filename unknown>:0
  at Microsoft.WindowsAzure.Storage.Core.Util.AsyncStreamCopier`1[T].ProcessEndRead () <0x40377980 + 0x0003b> in <filename unknown>:0
  at Microsoft.WindowsAzure.Storage.Core.Util.AsyncStreamCopier`1[T].EndOperation (IAsyncResult res) <0x40397920 + 0x00067> in <filename unknown>:0
  at Microsoft.WindowsAzure.Storage.Core.Util.AsyncStreamCopier`1[T].EndOpWithCatch (IAsyncResult res) <0x40397580 + 0x00073> in <filename unknown>:0
  --- End of inner exception stack trace ---
  at Microsoft.WindowsAzure.Storage.Core.Util.StorageAsyncResult`1[T].End () <0x403aae00 + 0x00037> in <filename unknown>:0
  at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.EndUploadFromStream (IAsyncResult asyncResult) <0x403aad90 + 0x0004b> in <filename unknown>:0
  at Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions+<>c__DisplayClass4.<CreateCallbackVoid>b__3 (IAsyncResult ar) <0x403aaa90 + 0x000d4> in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x7ffa5bc016d0 + 0x00029> in <filename unknown>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0x7ffa5bbff6b0 + 0x000a7> in <filename unknown>:0
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0x7ffa5bbff630 + 0x0006b> in <filename unknown>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0x7ffa5bbff5e0 + 0x0003a> in <filename unknown>:0
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () <0x7ffa5bbff5c0 + 0x00012> in <filename unknown>:0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment