C
C#6mo ago
BlueHelmet

Blazor NavigationManager throws Unspecified navigation exeption.

So i've just started to learn Blazor. I found that when i try to use the NavigationManager from a form (OnValidSubmit), then it throws: Microsoft.AspNetCore.Components.NavigationException: 'Exception_WasThrown' I have not edited any of the setup (program.cs), so i might just be a bug in the framework as there is some bugs on the navigation manager. I have not been able to find any cases exactly like this on their github. It only throws the exception in Debug, and if i continue, the navigation is executed correctly. I have also tried to "hack", by using NavigationManager.NavigateTo() with the current page as parameter, throws same error. Does anyone know if this is a known error and if there might be a workaround (or if there is something i am missing). Code
<EditForm
Model="server"
FormName="@($"form-server-{server.ServerId}")"
OnValidSubmit="@(() => {DeleteServer(server.ServerId);})">
<button type="submit" class="btn btn-primary">Delete</button>
</EditForm>
<EditForm
Model="server"
FormName="@($"form-server-{server.ServerId}")"
OnValidSubmit="@(() => {DeleteServer(server.ServerId);})">
<button type="submit" class="btn btn-primary">Delete</button>
</EditForm>
private void DeleteServer(int serverId)
{
if (serverId > 0)
{
ServerRepository.DeleteServer(serverId);
NavigationManager.Refresh();
}
}
private void DeleteServer(int serverId)
{
if (serverId > 0)
{
ServerRepository.DeleteServer(serverId);
NavigationManager.Refresh();
}
}
Exception: See added image See first comment for stacktrace.
No description
4 Replies
BlueHelmet
BlueHelmetOP6mo ago
tacktrace:
at Microsoft.AspNetCore.Components.Endpoints.HttpNavigationManager.NavigateToCore(String uri, NavigationOptions options)
at Microsoft.AspNetCore.Components.NavigationManager.Refresh(Boolean forceReload)
at ServerManagement.Components.Pages.Servers.DeleteServer(Int32 serverId) in C:\Repos\BlazorDeepDive\ServerManagement\Components\Pages\Servers.razor:line 53
at ServerManagement.Components.Pages.Servers.<>c__DisplayClass0_0.<BuildRenderTree>b__0() in C:\Repos\BlazorDeepDive\ServerManagement\Components\Pages\Servers.razor:line 35
at Microsoft.AspNetCore.Components.EventCallbackWorkItem.InvokeAsync[T](MulticastDelegate delegate, T arg)
at Microsoft.AspNetCore.Components.ComponentBase.Microsoft.AspNetCore.Components.IHandleEvent.HandleEventAsync(EventCallbackWorkItem callback, Object arg)
at Microsoft.AspNetCore.Components.EventCallback`1.InvokeAsync(TValue arg)
at Microsoft.AspNetCore.Components.Forms.EditForm.<HandleSubmitAsync>d__46.MoveNext()
at Microsoft.AspNetCore.Components.Endpoints.HttpNavigationManager.NavigateToCore(String uri, NavigationOptions options)
at Microsoft.AspNetCore.Components.NavigationManager.Refresh(Boolean forceReload)
at ServerManagement.Components.Pages.Servers.DeleteServer(Int32 serverId) in C:\Repos\BlazorDeepDive\ServerManagement\Components\Pages\Servers.razor:line 53
at ServerManagement.Components.Pages.Servers.<>c__DisplayClass0_0.<BuildRenderTree>b__0() in C:\Repos\BlazorDeepDive\ServerManagement\Components\Pages\Servers.razor:line 35
at Microsoft.AspNetCore.Components.EventCallbackWorkItem.InvokeAsync[T](MulticastDelegate delegate, T arg)
at Microsoft.AspNetCore.Components.ComponentBase.Microsoft.AspNetCore.Components.IHandleEvent.HandleEventAsync(EventCallbackWorkItem callback, Object arg)
at Microsoft.AspNetCore.Components.EventCallback`1.InvokeAsync(TValue arg)
at Microsoft.AspNetCore.Components.Forms.EditForm.<HandleSubmitAsync>d__46.MoveNext()
Zendist
Zendist6mo ago
It throws, but still works? Huh? Are you catching an exception that gets caught by the framework and is ignored, perhaps?
friedice
friedice6mo ago
I personally never ran into that issue. What's your .razor look like? Are you using WASM, server, or auto?
BlueHelmet
BlueHelmetOP6mo ago
I found that you could disable that type if exeption in debug mode. Apparently it is a known thing that the navigator throws an exception and handles it somewhere else. When running without debugging no errors occurs. For now i am not using any interactivity (why i need to call the refresh function)
Want results from more Discord servers?
Add your server