Search code examples
c#asp.net-coreblazor

JS Runtime Cancellation Token timeout error in ASP.NET core


I'm building an ASP.NET core application with ef core. When I try to show a Popup that doesn't have a timeout with this command:

await _jsRuntime.InvokeAsync<Task>("showVersionUpdate", version, System.Threading.CancellationToken.None);

I get the following error:

System.NotSupportedException: 'Serialization and deserialization of 'System.IntPtr' instances is not supported. Path: $.WaitHandle.Handle. NotSupportedException: Serialization and deserialization of 'System.IntPtr' instances is not supported. '

Any help is appreciated!

PS: I've tried removing the cancellation token completely but it still timesout after a couple of seconds. The showVersionUpdate is a sweetalert2 popup


Solution

  • Try using

    await _jsRuntime.InvokeVoidAsync("showVersionUpdate", version);
    

    All cancellable Invoke...Async expect the cancellation token as the second parameter followed by a params object?[]? args list of parameters. The question's code is trying to send the CancellationToken to the browser.

    Javascript methods that don't return anything should be called using the InvokeVoidAsync extension method, not an arbitrary result type.