Today a Blazor Server App I've been developing daily for a couple of weeks suddenly started throwing an exception in _Host.cshtml when I launch it in debug mode from within Visual Studio 2022. The error is shown in the attached image.
Current state of _Host.cshtml
@page "/"
@namespace Ano.Blazor.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = "_Layout";
}
<component type="typeof(App)" render-mode="ServerPrerendered" />
<link rel="stylesheet" href="_content/Radzen.Blazor/css/standard-base.css"/>
<script src="_content/Radzen.Blazor/Radzen.Blazor.js"></script>
Here is App.razor, the component that seems to be throwing an exception in _Host.cshtml
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
<Ano.Blazor.Pages.RedirectToLogin></Ano.Blazor.Pages.RedirectToLogin>
</NotAuthorized>
</AuthorizeRouteView>
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
The odd thing about this is that I had not made any changes to _Host.cshtml or App.razor when the exception first appeared. What I had just done was add scaffolded items for Identity, specifically the ConfirmEmail razor page.
The use of Radzen components was added yesterday and has been causing no issues. But to rule it out I tried running the app with references to the Radzen css and js removed. The exception persisted.
I have combed through every file in the solution at this point, looking for anything that could cause this. The app builds and rebuilds without errors. The exception doesn't tell me much about where the problem could be.
For comparison, I cloned the previous push to a separate folder, launched the solution in a new instance of VS 2022, ran the app in debug mode and it started normally. This got me thinking perhaps the solution itself is at fault. Corrupted? I deleted the .vs folder and allowed the original solution to recreate it but afterward the exception persists.
Has anyone seen this problem before?
UserManager<>
in the screens you scaffolded. You maybe usingUserManager<ApplicationUser>
and they are trying to injectUserManager<IdentityUser>
– Lithotomy