You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Blazor应用部署至Azure App Service报错:Components.Routes未找到

解决Blazor部署到Azure App Service后找不到Routes组件的异常

针对你遇到的Root component type '*.Components.Routes' could not be found in the assembly '**'异常,以下是具体排查和解决步骤:

1. 核对命名空间与程序集一致性

  • 检查App.razor中引用的Routes组件命名空间是否准确,确保*.Components.Routes与实际项目中Routes.razor的命名空间完全匹配(尤其注意项目重命名后可能出现的不一致)
  • 打开项目文件(.csproj),确认<AssemblyName>节点的值与错误提示中的程序集名称**一致

2. 验证发布配置与文件完整性

  • 发布时确保选择Release配置,且发布向导中勾选了「删除目标中的现有文件」
  • 本地执行dotnet publish -c Release生成发布包,手动上传到Azure App Service的wwwroot目录,排除IDE发布工具的潜在问题

3. 检查Blazor Routes组件配置

  • 确认项目Components文件夹下存在Routes.razor文件,且文件内容包含正确的路由逻辑(示例如下):
<Router AppAssembly="@typeof(Program).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>
  • 若使用.NET 8+的Blazor Web App模板,可暂时将@rendermode="InteractiveAuto"改为@rendermode="InteractiveServer",排查WebAssembly加载环节的问题

4. 启用Azure日志调试

  • 登录Azure门户,进入目标App Service的「日志」选项卡,开启应用日志记录和详细错误日志
  • 通过「高级工具(Kudu)」进入D:\home\LogFiles\Application目录,查看生成的日志文件,获取程序集加载失败的详细原因

5. 确认程序集部署状态

  • 用Kudu工具进入D:\home\site\wwwroot,检查项目对应的.dll文件是否存在,且版本与本地发布包一致
  • 若程序集缺失,重新发布或手动上传对应文件

内容的提问来源于stack exchange,提问作者Khandakar Rashed Hassan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 12:03:12