-
Notifications
You must be signed in to change notification settings - Fork 370
storageAsyncResult.End(); throws NullReferenceException.. most times. #202
Comments
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! |
Hi, here is the project.json from my DAL lib. |
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;
}
} |
Current situation is the following image work |
Hi @mkarlsson , it seems from your 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! |
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! |
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 |
ping |
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? |
I am seeing this exception intermittently. I'm using WindowsAzure.Storage 6.1.1-preview
Github repo with code is available: 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) |
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? |
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? |
hi @pemari-msft aspnet/HttpAbstractions#517 (comment) the same issue. |
@pemari-msft |
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. |
@pemari-msft
|
Here is a quick repro I set up with a template asp.net 5 MVC site. Adding this image works: https://dl.dropboxusercontent.com/u/1052402/storageerror/WIN_20151118_13_39_14_Pro.jpg |
Thanks @mkarlsson! I'll try to take a closer look soon. |
I have same issue on it. |
Tried suggestion by @gongdo , like this and it works. |
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 |
I have same issue too when using IFormFile.OpenReadStream and passing that stream to CloudBlockBlob.UploadFromStreamAsync(). Issue happens on random file names, for example: WRONG NAMES: 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. |
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. |
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 |
I investigate this issue and have found the cause of the bug aspnet/HttpAbstractions#602. |
This should also be fixed in the Azure storage SDK. |
The code here should be flowing the
and
|
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. |
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.
I'm not expecting any evident improvement over using UploadFromByteArrayAsync, obviously. |
Yep that's a workaround. The only thing to look out for is buffering all of that data in memory... |
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:
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:
Here is a repo with the code to reproduce the errors with both methods: https://github.com/pbedat/azure-mono-bug 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. |
I have the exact same problem with the versions: The code from @bragma seems to work for me. Thanks. |
\cc @asorrin-msft |
If it's of any help, the issue still persists on Mono with this version:
Running the same code on Windows works fine. Using the non-async versions of the methods works on both Windows and Ubuntu.
|
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:
/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"
The text was updated successfully, but these errors were encountered: