SignalR client method calling C#/JS interop, hangs indefinitely.
Hey all, I have a project that I've been working on that involves heavy usage of SignalR and C#/JS interop.
The basic flow goes like this:
1. On SignalR connect, send the client a message
GetDimensions
that the client acts on.
2. When client receives GetDimensions
, call C# service class that imports JS module
3. C# service class calls JS function to grab screen dimensions, await result
4. Return result as ValueTask<ScreenDimensions>
from service class.
5. Call the SignalR hub SetScreenDimensions
method with the return from the service class.
My problem: This is working fine on Linux, but on Windows (using Edge and Chrome), the code I've noted with // THIS HANGS HERE
won't run. I can see in teh JS console that I'm reaching that client method, but that call I'm awaiting hangs indefinitely.
Code samples:
Client Receive Method
ScreenInfo class method:
Anything glaringly wrong? I can't figure out why this call would work on Linux, but it would hang on Windows.
dotnet version: 7.0.4023 Replies
there could be a different problem here though, as the Linux machine I run on is very beefy
and the Windows machine is a normal laptop
Sounds vaguely like a deadlock. I don't know anything about JS interop, but does adding
ConfigureAwait(false)
to your await statements help?
As in:
Tried that, and it didnt' help. I have isolated it to that service function I'm calling...
I copied the code into a global JS function, and called that with the
IJSRuntime
instance rather than importing and calling a module, that unblocked me and now things are working...
It has to be a deadlock, something about trying to import the module and invoke the module, while also answering a SignalR hub call... idk