Description
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
- Create a Blazor Server application
- Use interactive server as global rendermode
- Add in the App.razor or somewere else the Toasts component with the interactive server rendermode.
- In any page inject the ToastService
- 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.