最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - JS Runtime Cancellation Token timeout error in ASP.NET core - Stack Overflow

programmeradmin1浏览0评论

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

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

Share Improve this question edited Feb 6 at 11:37 Panagiotis Kanavos 131k16 gold badges203 silver badges265 bronze badges asked Feb 6 at 10:00 KentKent 271 silver badge6 bronze badges 6
  • There are no relational databases in WebAssembly and browsers don't understand what types like CancellationToken. it still timesout after a couple of seconds what times out and what's the error message? The Javascript call? The EF call? The server-side push to the client? – Panagiotis Kanavos Commented Feb 6 at 10:55
  • What kind of project is this and where does it execute? Blazor WebAssembly runs on the browser itself, where there are no databases and threads are weird. Blazor Server runs on the server, and any attempts to run JS actually result in a push notification to the browser containing the serialized parameters that ends up calling the Javascript code. And as I said, there are no CancellationTokens in a browser. Please specify the application type and enough code to demonstrate the problem in the question itself. – Panagiotis Kanavos Commented Feb 6 at 10:59
  • BTW the JSRuntime.InvokeAsync docs show that the cancellation token is the second argument, not the last. Instead of using a cancellation token with InvokeAsync, the code is trying to pass it to JavaScript. Have you tried using await _jsRuntime.InvokeVoidAsync("showVersionUpdate", CancellationToken.None, version); ? – Panagiotis Kanavos Commented Feb 6 at 11:34
  • I've tried removing the cancellation token completely but it still timesout after a couple of seconds. you mean the popup times out after a couple of seconds? What does showVersionUpdate contain? Why would a JS method take seconds to complete? Unless it blocks waiting for the user to confirm? – Panagiotis Kanavos Commented Feb 6 at 11:37
  • If you're not returning anything from your JavaScript function then use InvokeVoidAsync and not InvokeAsync with a returned Task. – GH DevOps Commented Feb 6 at 11:50
 |  Show 1 more comment

1 Answer 1

Reset to default 1

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.

发布评论

评论列表(0)

  1. 暂无评论