Blazor - Copying Razor Page Causes Error 'System.NullReferenceException' in System.Private.CoreLib.dll
I have a brand new .Net6 Blazor App, rendered side, with a newly added page at /pages/scorer.razor
which runs and debugs without issue.
When I copy the .razor
page to a new page, eg from /pages/scorer.razor
to /pages/mudscorer.razor
, the following error is thrown when attempting to debug the application:
Exception thrown: 'System.NullReferenceException' in System.Private.CoreLib.dll
Source: /pages/scorer.razor
@page "/Scorer"
@attribute [Authorize()]
@attribute [Authorize(Roles = "Scoring")]
<PageTitle>MudScorer</PageTitle>
<link href="css/SleepCareStyle.css" type="text/css" rel="stylesheet" />
<style type="text/css">
#dimScreen {
background: rgba(255, 255, 255, 0.5);
height: 100%;
left: 0;
margin: 0;
padding: 0;
position: fixed;
top: 0;
width: 100%;
}
</style>
<table border="0" width="100%">
<tr>
<td class="SmallHeader">Scorer's Work List</td>
</tr>
<tr>
<td>
<ScorerWorkList></ScorerWorkList>
</td>
</tr>
</table>
Source: /pages/mudscorer.razor
@page "/Scorer"
@attribute [Authorize()]
@attribute [Authorize(Roles = "Scoring")]
<PageTitle>MudScorer</PageTitle>
<link href="css/SleepCareStyle.css" type="text/css" rel="stylesheet" />
<style type="text/css">
#dimScreen {
background: rgba(255, 255, 255, 0.5);
height: 100%;
left: 0;
margin: 0;
padding: 0;
position: fixed;
top: 0;
width: 100%;
}
</style>
<table border="0" width="100%">
<tr>
<td class="SmallHeader">Scorer's Work List</td>
</tr>
<tr>
<td>
<ScorerWorkList></ScorerWorkList>
</td>
</tr>
</table>
Make the @page
directive unique otherwise the router won't know how to route requests for /Scorer
Source: /pages/mudscorer.razor
@page "/MudScorer"
^^^
for example
Incidentally, not sure why you didn't get a bit more help out of the subsystem. When I make duplicated @page directives I see:
It's one of my favorite runtime errors to cause these days - that and adding some new thing, forgetting to register it in DI and getting Cannot provide a value for property 'X' on type 'Y'. There is no registered service of type 'Z'. Classic copy pasta mistake, every time!