I'm having the following error in the browser console that is not allowing the Blazor Webassembly app to continue consuming the grpc API:
System.ArgumentException: The base-type Grpc.Core.ClientBase for service-proxy CalibrationSaaS.Application.Services.IBasicsServices`1[ProtoBuf.Grpc.CallContext] lacks a suitable CallInvoker API
The code where this is happening is the following:
var httpClient = new HttpClient(new GrpcWebHandler(GrpcWebMode.GrpcWeb, new HttpClientHandler()));
using (var channel = Grpc.Net.Client.GrpcChannel.ForAddress(builder.Configuration["Kestrel:Endpoints:Http3:Url"], new GrpcChannelOptions
{
HttpClient = httpClient
}))
{
var a = channel.CreateGrpcService<Application.Services.IBasicsServices<CallContext>>(); //The error happens in this line of code
var b = await a.GetRoles(CallContext.Default); //This method is implemented
return b;
}
This error only happens when the application is published in the respective IIS, in the development IDE debug environment works normally.
Does anyone have an idea about what the problem could be?
It was a third party library issue (protobuf-net) that was fixed promptly by his creator. If you need more information you can check this thread:
https://github.com/protobuf-net/protobuf-net.Grpc/issues/247
To fix this, update the library to the version to 1.0.171 from Github and add to the Blazor project file the following configuration:
<PropertyGroup>
...
<BlazorWebAssemblyEnableLinking>false</BlazorWebAssemblyEnableLinking>
...
</PropertyGroup>