Azure-sdk-for-net: Blob upload fails when run in Blazor WebAssembly

Created on 28 Apr 2020  路  4Comments  路  Source: Azure/azure-sdk-for-net

Describe the bug
The UploadAsync call fails when run in Blazor WebAssembly. Here is my sample code:

public async Task UploadPayload(Stream payload)
{
  BlobClient client = new BlobClient("myConnectionString", "container", "bla");
  await client.UploadAsync(payload);
}

Expected behavior
The call succeeds

Actual behavior (include Exception or Stack Trace)
I get the following error:
System.Threading.SynchronizationLockException: Cannot wait on monitors on this runtime.

To Reproduce

  • Using latest VS 2019 preview (16.6 Preview 4)
  • Installed 3.1.3 SDK

Create a new Blazor WebAssembly application (3.2. Preview5 version):

  • dotnet new -i Microsoft.AspNetCore.Components.WebAssembly.Templates::3.2.0-preview5.20216.8
  • dotnet new blazorwasm
  • Add reference to <PackageReference Include="Azure.Storage.Blobs" Version="12.4.1" /> package
  • Update the Pages/Counter.razor as follows (Note: replace myConnectionString with a valid Blob storage connection string)
  • Run the app, go to the /counter page and click the Click Me button
@page "/counter"
@using Azure.Storage.Blobs
@using System.IO

<h1>Counter</h1>

<p>Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
    private int currentCount = 0;

    private async Task IncrementCount()
    {
        using MemoryStream payload = new MemoryStream();
        using StreamWriter sr = new StreamWriter(payload);
        sr.WriteLine("Sample payload to upload");
        sr.Flush();
        payload.Position = 0;

// The above code is simply to simulate a payload
        BlobClient client = new BlobClient("myConnectionString", "container", "bla");
        await client.UploadAsync(payload);
    }
}

Environment:

  • Name and version of the Library package used: Azure.Storage.Blobs v.12.4.1
  • Hosting platform or OS and .NET runtime version (dotnet --info output for .NET Core projects): .NET Core Runtime: 3.1.3
    OS: Win 10 Pro x64
  • IDE and version : VS 16.6 Preview4
Azure.Core Client customer-reported question

All 4 comments

Confirmed fixed with a latest Azure.Core build.

Thank you so much for handling this so fast, @pakrym!
Any hints regarding when should I expect this fix to be released?

This Friday the Azure.Core would ship so customers would have a workaround of updating it. I'm not sure if storage would also ship with updated Azure.Core dependency but the probability is high.

@mkArtakMSFT is there an easy way to run our tests in blazor runtime?

Unfortunately there is no easy way at the moment. We currently handle this manually, but the Mono team is working with the infrastructure team to spin up an internal hardware lab, where we will eventually be able to run automated tests against Mono WebAssembly runtime.

Was this page helpful?
0 / 5 - 0 ratings