将Blazor服务器站点5升级到6时出现问题



我做到了:

  1. 创建新的6.0项目
  2. 将所有组件和代码等复制到新项目
  3. 将我以前在Startup.cs中的服务添加到Program.cs
  4. 将我的全局using移动到新文件Globals.cs

代码编译并开始运行,但在爆炸之前从未显示任何内容。

问题

_Host.cshtml中,最后一行现在抛出一个空引用错误:

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

我知道这个问题很难回答,但我想知道是否有人能告诉我哪里可能出了问题。

定义"爆炸";。

我的猜测是它在加载在"/"路线正如你所说,当你的应用程序爆炸时,Net6中引入了一些错误报告问题。例如,请参见-https://github.com/dotnet/aspnetcore/issues/38380.

试着创建一个最小的应用程序,看看会发生什么——没有路由器,只有一些简单的html输出。看看会发生什么。然后添加路由器,但有固定的内容,看看路由器是否可以。我在下面添加了一些代码,向你展示了要尝试的东西。

@*<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>

最新更新