Skip to content

InvalidOperationException thrown when using the ToastService after asynchronous operations #836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Suiram1701 opened this issue Aug 8, 2024 · 0 comments

Comments

@Suiram1701
Copy link

Suiram1701 commented Aug 8, 2024

Describe the bug
When you use the ToatService after an asynchronous operation an InvalidOperationException is throwed: System.InvalidOperationException: The current thread is not associated with the Dispatcher. Use InvokeAsync() to switch execution to the Dispatcher when triggering rendering or component state.. The Toast that should be created using the ToastService appears as expected but with the exception.
It is possible to fix this issue if you wrap the ToastService call in a InvokeAsync(() => { }) call but it would be nice if I don't have to do this on every ToastService call.

To Reproduce

  1. Create a Blazor Server application
  2. Use interactive server as global rendermode
  3. Add in the App.razor or somewere else the Toasts component with the interactive server rendermode.
  4. In any page inject the ToastService
  5. Add a button to this page that performs on click an asynchronous operation and after this the ToastService should notify the user (I'am not sure why but not every async operation causes this issue. In my case often at Db queries).

Expected behavior
Using the ToastService after async operation without the risk of throwing an exception.

Versions:

  • .NET Version: .NET 8
  • BlazorBootstrap: 3.0.0-preview-3
  • Blazor WebAssembly / Server: Server
  • Blazor Interactive Render Mode: Interactive Server
  • Blazor Interactivity Location: Global

Desktop:

  • OS: Windows 11
  • Browser Chrome

Smartphone: Not tested on mobile device because it's a server-side issue.

Suiram1701 added a commit to Suiram1701/blazorbootstrap that referenced this issue Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants