小编LNX*_*LNX的帖子

Blazor 服务器应用程序组件突然抛出空引用异常

今天,当我在 Visual Studio 2022 中以调试模式启动 Blazor 服务器应用程序时,我几周来每天开发的 Blazor 服务器应用程序突然开始在 _Host.cshtml 中引发异常。错误如附图所示。

在此输入图像描述

_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>
Run Code Online (Sandbox Code Playgroud)

这是 App.razor,该组件似乎在 _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>
Run Code Online (Sandbox Code Playgroud)

奇怪的是,当异常第一次出现时,我没有对 _Host.cshtml 或 App.razor 进行任何更改。我刚刚所做的是为身份添加脚手架项目,特别是ConfirmEmail 剃刀页面。

昨天添加了 Radzen 组件的使用,并且没有引起任何问题。但为了排除这种情况,我尝试运行应用程序并删除对 …

blazor

8
推荐指数
1
解决办法
2408
查看次数

标签 统计

blazor ×1