Blazor Web项目启动报错:无法加载RenderModeInteractiveAutoAttribute类型
解决Blazor Web中System.TypeLoadException错误
针对你遇到的System.TypeLoadException(无法加载RenderModeInteractiveAutoAttribute类型)问题,可按以下步骤排查修复:
1. 确认项目目标框架为.NET 8
RenderModeInteractiveAutoAttribute是.NET 8 Blazor新增的类型,若项目目标框架低于.NET 8,会触发此错误:
- 右键项目 → 属性 → 应用 → 目标框架,选择
.NET 8
2. 统一NuGet包版本
确保所有Blazor相关的NuGet包版本一致且为8.0.x:
- 打开项目的
.csproj文件,检查并修改包版本:<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.*" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.*" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.*" /> - 执行
dotnet restore命令重新还原包
3. 清理并重建项目
缓存的旧编译文件可能导致版本冲突:
- 执行
dotnet clean清理项目 - 执行
dotnet build重新编译 - 重启IDE(如Visual Studio)
4. 验证代码兼容性
你当前使用的.AddInteractiveServerRenderMode()和.AddInteractiveWebAssemblyRenderMode()是.NET 8的标准API,代码本身无问题,错误根源仍为版本不匹配,完成上述步骤后即可正常运行。
内容的提问来源于stack exchange,提问作者BrooklynSon
相关产品推荐
相关产品推荐

