I have a simple application but it stops working on page initialization with error
NullReferenceException: Object reference not set to an instance of an object. Site.Shared.MainLayout.BuildRenderTree(RenderTreeBuilder __builder) Error: enter image description here
But there is nothing complicated in the code. App.razor:
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
_Host.cshtml: enter image description here
MainLayout.razor: enter image description here
StartUpService.cs: enter image description here
page.GetPageGlobalAsync() is working well, I can pass this method in the debug mode. enter image description here
But after I have this error. And have no idea what is the reason and how can I get more information about what is wrong.
UPD
If I change code to:
PageGlobal page = new PageGlobal()
And it started working but OnInitializedAsync is the async method, why I cannot use async-await methods in the OnInitializedAsync method?