aspnetcore: Blazor doesn't render ErrorBoundary's ErrorContent when there are two different exceptions inside it's ChildContent
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
ErrorBoundary renders nothing when there are two different errors inside it’s ChildContent.
Expected Behavior
ErrorBoundary renders exception information.
Steps To Reproduce
App.razor
<ErrorBoundary>
<ChildContent>
<ComponentWithError />
</ChildContent>
<ErrorContent>
<div style="background: red">@context</div>
</ErrorContent>
</ErrorBoundary>
ComponentWithError.razor
@{
throw new Exception("error2");
}
@code
{
protected override async Task OnInitializedAsync()
{
throw new Exception("error");
}
}
Exceptions (if any)
No response
.NET Version
6.0.101
Anything else?
I originally ran into this problem when I misspelled the parameter name in the inner component of ComponentWithError:
<ComponentWithoutProp BadProp=1 />
Which throws an exception by itself.
Also with exception inside void OnInitialized() everything works fine.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 6
- Comments: 16 (9 by maintainers)
I’d like this to get some more attention than just pushing it back from one year to the next. This has been around since .NET 6, and now you have three releases with this same issue.
I can confirm that this is an issue for me as well. The ErrorBoundary should be catching and rendering its ErrorContent if some async work in OnInitializedAsync throws shouldn’t it? Instead it bubbles up to the whole application, whereas I want it to do what it claims to do. Keep it within the component’s ErrorBoundary and handle it there.
I tried to make a minimal reproducible example. Of course there is much more code to
awaitin real use case.Hi @TanayParikh. You removed
asyncfrom my method and the problem is gone.I reproduced it by adding
asyncback: https://blazorrepl.telerik.com/cQPuQTml54XlfWdS53And the following does not work:
https://blazorrepl.telerik.com/mcbucUvh06LNyOkj40
So the
asyncisn’t the issue per-say, it’s the missingawaitif you haveasync. The following works as expected:https://blazorrepl.telerik.com/GQFuGAFq46B8euzE23