Bennyboy1973
Bennyboy1973

Reputation: 4208

Trouble upgrading Blazor Server site 5 to 6

I did:

  1. Create new 6.0 project
  2. Copy all components and code etc. to new project
  3. Add my services that used to be in Startup.cs to Program.cs
  4. Move my global usings to a new file, Globals.cs

The code compiles and begins to run, but never shows anything before it explodes.

The problem

In _Host.cshtml, the last line now throws a null reference error:

@page "/"
@namespace BEC.web.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
    Layout = "_Layout";
}
<component type="typeof(App)" render-mode="ServerPrerendered" />

I know this question is hard to answer, but I'm wondering if anyone can shed a little light on where I might have gone wrong.

Upvotes: 1

Views: 171

Answers (1)

MrC aka Shaun Curtis
MrC aka Shaun Curtis

Reputation: 30046

Define "Explodes".

My guess is its in one of the components being loaded in the "/" route. There are a few problems in error reporting that have been introduced in Net6 when, as you put it, your app explodes. See for example - https://github.com/dotnet/aspnetcore/issues/38380.

Try creating a minimal App and see what happens - no router, just some plain html output. See what happens. Then add the router, but with fixed content to see if the router is OK. I've added some code below to show you the sort of stuff to try.

@*<Router AppAssembly="@typeof(App).Assembly">
    <Found Context="routeData">
    <RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
    <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>
*@
@* Step 1*@
Hello World

@* Step 2*@
<Router AppAssembly="@typeof(App).Assembly">
    <Found Context="routeData">
        Found
    </Found>
    <NotFound>
        Not Found
    </NotFound>
</Router>

@* Step 3*@
<Router AppAssembly="@typeof(App).Assembly">
    <Found Context="routeData">
        <StackOverflow.Server.Pages.Index />
    </Found>
    <NotFound>
        Not Found
    </NotFound>
</Router>

Upvotes: 1

Related Questions