Closed Liero closed 1 year ago
@Liero thanks for contacting us.
Blazor like other UI technologies uses a synchronizationcontext to ensure a consistent programming model across Wasm, Server and Desktop. For that reason you need to call StateHasChanged within the Blazor context.
In your case it is being called from a background thread that is not associated with the current circuit, which is what is causing your problem.
To solve it, you need to call .Subscribe(() => Invoke(() => StateHasChanged()));
instead.
@javiercn : Yes, it's a bug in my app, but it should not terminate the whole process, should it? I'm 99% positive this wasn't the case in .NET 6.
I've created a minimal repo, see original post
@Liero I'd be surprised if it doesn't.
An exception is happening in a background thread, we do not have a way to observe that, nor do we have context on when it is happening.
My expectation is that it indeed causes the app to crash.
In general, exception in background thread does not cause the app to crash. This is true even in blazor.
I can throw any number of custom exceptions in background threads and nothing happens to the app. The exception is swallowed, background thread exits and app continues to run
I found out, that it crashes only when trying to access component reference from background thread. If I only call StateHasChanged() from backround thread, the same InvalidOperationException is thrown, but the app continues to run.
This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.
See our Issue Management Policies for more information.
Is there an existing issue for this?
Describe the bug
After I upgraded to .NET 7, my Blazor Server app deployed to IIS on premises is being restarted with following logs:
The code causing the InvalidOperation execption is follwing:
Expected Behavior
The exception should only affect currect blazor session, not the entire blazor app.
w3wp.exe should not crash
Steps To Reproduce
You will see following error in all opened tabs (not just the clicked one):
Exceptions (if any)
.NET --info