-
Notifications
You must be signed in to change notification settings - Fork 494
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
Cosmos client fails in Blazor WebAssembly app #1429
Comments
I think it can be fixed by mono team, their mono wasm sdk is responsible to run regular .net libraries like cosmos client in browser. |
I haven't tested it with the latest preview yet, but it seems to be working with the current version of Blazor. Please check out the PR adding it as a sample. |
@j82w Yes, Blazor Server works fine. It's Blazor WebAssembly that has the issue. |
@Lupusa87 the issue looks like it is related to the special HttpClient that is configured by Blazor. I don't think the mono team can fix this, we need the CosmosClient SDK to allow us to pass in a HttpClient or IHttpClientFactory (if that is feasible). |
@JeremyLikness Is the scenario WebAssembly with ASP.NET Core or without? I'm looking at how Blazor handles the HttpClient instance provisioning. |
@ealsur either version works ... the ASP.NET Core just hosts the static files and makes it easier to set up server-side APIs, but the client project should work the same and provision the same. I'm trying to make it work without ASP.NET Core. |
Required code changes were merged, will be available in the next release. |
#1429 added support for HttpClientFactory inside the gateway connection mode, but the DocumentClient was maintaining two other HttpClient instances on GatewayAccountReader and GatewayAddressCache. If the user was trying to use a custom HttpClientFactory to use a single HttpClient instance, it was not reaching these classes. The effect also was that we were maintaining 3 different HttpClient instances normally. This PR unifies this into a single HttpClient, that can either be created or obtained from the HttpClientFactory.
Describe the bug
When instantiating an instance of CosmosClient in a Blazor WebAssembly app, the constructor throws an exception:
System.Threading.SynchronizationLockException: Cannot wait on monitors on this runtime.
To Reproduce
Create a new Blazor WebAssembly project. I used the latest preview (3.2.0 preview 5). Install
Microsoft.Azure.Cosmos
(I used 3.7.0-preview). InProgram.Main
add the following code anywhere:Replace the endpoint and key with an actual endpoint/key. The error will throw immediately.
Expected behavior
I would expect to be able to use the Cosmos client SDK from a Blazor client in gateway mode as it is simply HTTP.
Actual behavior
The client throws, likely due to using an invalid
HttpClient
instead of the one provided by Blazor via DI.Environment summary
SDK Version: 3.7.0-preview
OS Version: Windows 10
Visual Studio Version: 16.6.0 preview 4.0
.NET Core Version: 5.0.100-preview.3.20216.6
Blazor Version: 3.2.0-preview5.20216.8
Additional context
Full call stack from exception:
The text was updated successfully, but these errors were encountered: