Blazor Interactive Server - in my MainLayout.razor I have:
<ErrorBoundary><ChildContent><!-- lots of nodes --></ChildContent><ErrorContent Context="error"><main class="page--error"><div class="main-content"> @{ var guid = Guid.NewGuid().ToString(); Logger.LogError(error, $"{error.GetType().Name}: {guid}"); }<h1>Unexpected Error (sorry)</h1><p> The program has encountered an unexpected error (yes there are expected errors). This error has been logged and we will look at it.</p></div></main></ErrorContent></ErrorBoundary>When it throws an exception handling an event in one of my components, it never gets to the <ErrorContent>. Why not?
And what do I need to do to log the exception? I want to avoid having to try/catch everywhere just to log the exception.
In addition this occurs silently. No error is displayed to the user. I want to put up a message that says something happened, provide them an error number (guid) and ask them to contact support. I can then use that guid to find the issue in the logs to see what happened.
The code throwing the exception is fired off by OnSelectResources:
<SelectOrganizations Data="@_allOrganizations" Visible="@IsSelectResourcesVisible" Click="@OnSelectResources"/>Which is:
[Parameter]public EventCallback<IEnumerable<Organization>?> Click { get; set; }Which is declared as:
<DxButton RenderStyle="ButtonRenderStyle.Primary" Text="@Localizer["Select"]" Enabled="@(Values?.Count() > 0 && Values?.Count() <= @MaxAllowSelected)" Click="OnSelect" />And calls:
private void OnSelect(){ Visible = false; _receivedClick = true; if (Click.HasDelegate) Click.InvokeAsync(Values);}Update: As stated above, this is InteractiveServer mode. In App.razor I have:
<HeadOutlet @rendermode="RenderMode.InteractiveServer" /></head><body><Routes @rendermode="RenderMode.InteractiveServer" />