question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with your Blazor Example for gRPC-Web

See original GitHub issue

What version of gRPC and what language are you using?

2.30 - Net.Client.Web - C#

What operating system (Linux, Windows,…) and version?

Windows 10 2020

What runtime / compiler are you using (e.g. .NET Core SDK version dotnet --info)

.NET SDK (reflecting any global.json): Version: 5.0.100-preview.5.20279.10 Commit: 8139f1b74e

Runtime Environment: OS Name: Windows OS Version: 10.0.19041 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\5.0.100-preview.5.20279.10\

Host (useful for support): Version: 5.0.0-preview.5.20278.1 Commit: 4ae4e2fe08

.NET SDKs installed: 3.1.301 [C:\Program Files\dotnet\sdk] 3.1.302 [C:\Program Files\dotnet\sdk] 5.0.100-preview.5.20279.10 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.All 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.0-preview.5.20279.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.0-preview.5.20278.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.0-preview.5.20278.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download

What did you do?

I was trying to run your Blazor Example but it does not work : https://github.com/grpc/grpc-dotnet/tree/master/examples/Blazor It does not work and client cannot receive messages. getting Exception instead,… 😦

What did you expect to see?

Well simple no error

What did you see instead?

image

Data fetched from a gRPC service.

at Client.Pages.FetchData.OnInitializedAsync () <0x2241dc8 + 0x0011a> in <filename unknown>:0 Status(StatusCode=“Internal”, Detail=“Error starting gRPC call. JSException: TypeError: Failed to fetch”, DebugException="WebAssembly.JSException: TypeError: Failed to fetch at System.Net.Http.WebAssemblyHttpHandler.doFetch (System.Threading.Tasks.TaskCompletionSource1[TResult] tcs, System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) <0x231d480 + 0x00a54> in <filename unknown>:0 at System.Net.Http.WebAssemblyHttpHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) <0x23015e0 + 0x001be> in <filename unknown>:0 at Grpc.Net.Client.Web.GrpcWebHandler.SendAsyncCore (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) <0x22e6d60 + 0x001a0> in <filename unknown>:0 at Grpc.Net.Client.Internal.GrpcCall2[TRequest,TResponse].RunCall (System.Net.Http.HttpRequestMessage request, System.Nullable`1[T] timeout) <0x22ddbf8 + 0x003ec> in <filename unknown>:0 ")

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).

See TROUBLESHOOTING.md for how to diagnose problems better.

Anything else we should know about your project / environment?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
michalsscommented, Jul 30, 2020

Ok sorted: i guess this is my bad… 😦 shame on me but still if you select iis it works with classic http clinet server model… Well ok i know this now… thx for all help…

image

0reactions
roboriaancommented, Oct 28, 2021

In my case (my client and server have different ports), i’ve enabled CORS and it fix the problem. Everything works, including client and server projects under debug in single VS instance.

public void ConfigureServices(IServiceCollection services)
{
  services.AddGrpc();

  services.AddCors(o => o.AddDefaultPolicy(builder =>
  {
    builder.AllowAnyOrigin()
           .AllowAnyMethod()
           .AllowAnyHeader()
           .WithExposedHeaders("Grpc-Status", "Grpc-Message", "Grpc-Encoding", "Grpc-Accept-Encoding");
  }));
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
  app.UseRouting();
  app.UseGrpcWeb(new GrpcWebOptions { DefaultEnabled = true });
  app.UseCors();
  app.UseEndpoints(...);
}

I have this same configuration but still getting the cors error. If you don’t mind me asking. Did you setup your GrpcChannel on the client with specific channel options?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use gRPC-Web with Blazor WebAssembly on App ...
Open Visual Studio and Create a new project and search for Blazor app. Highlight Blazor app, click Next, name your application and click...
Read more >
Using gRPC-Web with Blazor WebAssembly - Steve Sanderson
If you're hosting a Blazor WebAssembly application on ASP.NET Core server, then by default you have three projects: client, server, and shared.
Read more >
10 Steps to Replace REST Services with gRPC-Web in ...
REST web services can be replaced with gRPC-Web in Blazor WebAssembly apps for limited-bandwidth scenarios. This can be achieved in 10 ...
Read more >
Blazor WebAssembly: Debugging gRPC-Web with Custom ...
If you are working with Blazor, gRPC is a big issue for transferring data from APIs to clients. One issue of developing with...
Read more >
How to Utilize gRPC-Web From a Blazor WebAssembly ...
In this post I will demonstrate consuming a gRPC-Web endpoint from within a Blazor WebAssembly application. Along the way I will also ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found