[英]The type or namespace name 'AspNetCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
[英]The type or namespace name 'Mvc' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?)
主要问题
以上只是我的 C# 项目中超过 1k+ 错误之一。 我正在使用带有 Catalina 10.15.6 的 2017 MacBook Pro。 和 VS 代码。 我拥有的 dotnet-SDK 是 3.1.401。 我尝试卸载并重新安装它,但没有奏效。 我有一个项目运行良好,然后昨晚我进行了brew upgrade
,今天我遇到了所有这些错误。 当然我试过dotnet restore
dotnet ef database update
这些命令成功地将包重新安装到项目目录并重新应用数据库迁移(这个项目使用 postgres 数据库以防万一很重要),但它仍然存在所有这些错误。
在我重新创建新的开发 SSL 证书后,我能够让项目在 Firefox 上运行。
当我像往常一样尝试运行应用程序并连接到“https://localhost:5001”时,我得到了这个
“安全连接失败 连接到 localhost:5001 时发生错误。PR_END_OF_FILE_ERROR 无法显示您尝试查看的页面,因为无法验证接收到的数据的真实性。请联系网站所有者告知此问题。 "
我使用以下命令修复了此问题dotnet dev-certs https --clean
然后dotnet dev-certs https
然后它开始在 Z763F7F1AEC350CD1A46238D1D5C3C+2 中的 Z763F7F1AEC350CD1A46238D1D5C3C+2 错误上正常工作,但仍然
综上所述
该项目有效,我只是在 VSCode 中有大量错误,我不确定是什么原因造成的。
错误样本
The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
The type 'Task' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
我有同样的问题,为我解决它的方法是:
dotnet 添加 package Microsoft.AspNetCore.Mvc.RazorPages --version 2.2.5
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
</PropertyGroup>
主要问题是 Microsoft.AspNetCore.MVC 命名空间不再存在。
请试试
dotnet dev-certs https --trust
https://www.hanselman.com/blog/DevelopingLocallyWithASPNETCoreUnderHTTPSSSLAndSelfSignedCerts.aspx
问题已在此处修复: https://github.com/OmniSharp/omnisharp-vscode/issues/3990
当我的 dotnet core sdk 更新到 3.1.401 时,我不得不更改涉及 mono 的 vscode 中的设置。
我转到文件 > 首选项 > 设置,然后搜索“omnisharp 使用全局单声道”并将结果值从“自动”更改为“从不”。 这在 linting 时停止了错误。
我想补充一点,在您的应用程序中调试此问题时,请查找是否出现 MVC。 我在 .net 5 上的 Blazor WebAssembly 应用程序中遇到了这个问题,发现问题是一个看似无害的 SelectList 属性,它位于 Mvc.Rendering 命名空间中,在我共享的 ZA2F2A2ED4F8EBC2CBB4ZC2 程序集库中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.