Blazor:命名空间 'Microsoft.AspNetCore.Mvc.ApplicationParts' 中不存在类型或命名空间名称 'ApplicationPartAttributeAttribute'
Blazor: The type or namespace name 'ApplicationPartAttributeAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Mvc.ApplicationParts'
我在尝试编译我的 Blazor WebAssembly 应用程序时遇到此错误。
error CS0234: The type or namespace name 'ApplicationPartAttributeAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Mvc.ApplicationParts' (are you missing an assembly reference?)
原因是因为我正在使用一个使用 Microsoft.AspNetCore.Mvc.Core
的库,它似乎与 blazor Web Assembly 不太兼容,
我确实测试了创建服务器端 blazor 应用程序,它工作正常。
有没有办法让错误“消失”?我想使用那个库,我想坚持使用 Blazor WA。
error CS0234: The type or namespace name
'ApplicationPartAttributeAttribute' does not exist in the namespace
'Microsoft.AspNetCore.Mvc.ApplicationParts' (are you missing an
assembly reference?)
首先,从官方文档中可以看出,class的名字应该是ApplicationPartAttribute
,而不是ApplicationPartAttributeAttribute
(attribute
是重复的)。请检查你的代码并修改它。
my main concern is why does it work in blazor serverside and not in
WA.
Microsoft.AspNetCore.Mvc.ApplicationParts
包在 Blazor 服务器端工作,而不在 WA 应用程序中工作。
对于这个问题,我假设您正在为此类应用程序创建主要 Blazor 托管模型或独立 Blazor WebAssembly 应用程序,它是 客户端 并且没有后端 ASP.NET 核心应用程序来提供其文件,因此您不能使用 ApplicationParts
.
但是,如果您创建一个 托管的 Blazor WebAssembly 应用程序:在创建 WebAssembly 应用程序时,选择“ASP.NET 核心托管”选项。
之后,Blazor WebAssembly 应用程序如下所示:
我们可以看到,应用程序包含三个项目,然后我们可以在服务器项目中使用ApplicationParts
。因此,您可以创建一个托管的 Blazor WebAssembly 应用程序。
更多详细信息,请参阅Blazor WebAssembly。
来自 this and this,我建议您不要引用支持页面和视图的 razor class 库,也不要引用面向 ASP.NET Core 的库。这在 Blazor Webassembly 中行不通。
我的建议是你从你的共享库中分解出你直接需要引用的 classes 并在你的 wasm 项目中使用它们,而不是引用整个库,你甚至可以分解那些 classes 并创建一个要引用的新库,而不依赖于 asp.net 核心框架。
我粘贴的其中一个链接的摘录说:“感谢您联系我们。这不是我们建议遵循的模式。您不能从 Blazor WebAssembly 应用程序引用 MVC 二进制文件。”
我的两分钱。
我有一个 blazor Wasm 应用程序,并收到以下错误。
Severity Code Description Project File Line Suppression State
Error CS0234 The type or namespace name 'ApplicationPartAttributeAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Mvc.ApplicationParts' (are you missing an assembly reference?) Mewurk.Hrms.Support.BlazorWasm D:\Mewurk\AdminConsole\src\Mewurk.Hrms.Support.BlazorWasm\obj\Debug\net6.0\Mewurk.Hrms.Support.BlazorWasm.MvcApplicationPartsAssemblyInfo.cs 14 Active
Severity Code Description Project File Line Suppression State
Error CS0234 The type or namespace name 'ApplicationPartAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Mvc.ApplicationParts' (are you missing an assembly reference?) Mewurk.Hrms.Support.BlazorWasm D:\Mewurk\AdminConsole\src\Mewurk.Hrms.Support.BlazorWasm\obj\Debug\net6.0\Mewurk.Hrms.Support.BlazorWasm.MvcApplicationPartsAssemblyInfo.cs 14 Active
在我添加对包含以下 nuget 包的 .net core 6 class 库项目的引用后,出现上述错误。
<PackageReference Include="Microsoft.AspNetCore.OData" Version="8.0.8" />
事实证明,class 库项目不需要它。所以我删除了错误消失了。
我在尝试编译我的 Blazor WebAssembly 应用程序时遇到此错误。
error CS0234: The type or namespace name 'ApplicationPartAttributeAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Mvc.ApplicationParts' (are you missing an assembly reference?)
原因是因为我正在使用一个使用 Microsoft.AspNetCore.Mvc.Core
的库,它似乎与 blazor Web Assembly 不太兼容,
我确实测试了创建服务器端 blazor 应用程序,它工作正常。
有没有办法让错误“消失”?我想使用那个库,我想坚持使用 Blazor WA。
error CS0234: The type or namespace name 'ApplicationPartAttributeAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Mvc.ApplicationParts' (are you missing an assembly reference?)
首先,从官方文档中可以看出,class的名字应该是ApplicationPartAttribute
,而不是ApplicationPartAttributeAttribute
(attribute
是重复的)。请检查你的代码并修改它。
my main concern is why does it work in blazor serverside and not in WA.
Microsoft.AspNetCore.Mvc.ApplicationParts
包在 Blazor 服务器端工作,而不在 WA 应用程序中工作。
对于这个问题,我假设您正在为此类应用程序创建主要 Blazor 托管模型或独立 Blazor WebAssembly 应用程序,它是 客户端 并且没有后端 ASP.NET 核心应用程序来提供其文件,因此您不能使用 ApplicationParts
.
但是,如果您创建一个 托管的 Blazor WebAssembly 应用程序:在创建 WebAssembly 应用程序时,选择“ASP.NET 核心托管”选项。
之后,Blazor WebAssembly 应用程序如下所示:
我们可以看到,应用程序包含三个项目,然后我们可以在服务器项目中使用ApplicationParts
。因此,您可以创建一个托管的 Blazor WebAssembly 应用程序。
更多详细信息,请参阅Blazor WebAssembly。
来自 this and this,我建议您不要引用支持页面和视图的 razor class 库,也不要引用面向 ASP.NET Core 的库。这在 Blazor Webassembly 中行不通。
我的建议是你从你的共享库中分解出你直接需要引用的 classes 并在你的 wasm 项目中使用它们,而不是引用整个库,你甚至可以分解那些 classes 并创建一个要引用的新库,而不依赖于 asp.net 核心框架。
我粘贴的其中一个链接的摘录说:“感谢您联系我们。这不是我们建议遵循的模式。您不能从 Blazor WebAssembly 应用程序引用 MVC 二进制文件。”
我的两分钱。
我有一个 blazor Wasm 应用程序,并收到以下错误。
Severity Code Description Project File Line Suppression State Error CS0234 The type or namespace name 'ApplicationPartAttributeAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Mvc.ApplicationParts' (are you missing an assembly reference?) Mewurk.Hrms.Support.BlazorWasm D:\Mewurk\AdminConsole\src\Mewurk.Hrms.Support.BlazorWasm\obj\Debug\net6.0\Mewurk.Hrms.Support.BlazorWasm.MvcApplicationPartsAssemblyInfo.cs 14 Active
Severity Code Description Project File Line Suppression State Error CS0234 The type or namespace name 'ApplicationPartAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Mvc.ApplicationParts' (are you missing an assembly reference?) Mewurk.Hrms.Support.BlazorWasm D:\Mewurk\AdminConsole\src\Mewurk.Hrms.Support.BlazorWasm\obj\Debug\net6.0\Mewurk.Hrms.Support.BlazorWasm.MvcApplicationPartsAssemblyInfo.cs 14 Active
在我添加对包含以下 nuget 包的 .net core 6 class 库项目的引用后,出现上述错误。
<PackageReference Include="Microsoft.AspNetCore.OData" Version="8.0.8" />
事实证明,class 库项目不需要它。所以我删除了错误消失了。