错误“类型或命名空间‘MyType’”无法找到(或者您是否缺少程序集引用?)”

发布于 2025-01-18 08:47:36 字数 626 浏览 4 评论 0原文

即使添加了“MyType”所在的命名空间,我也收到错误“无法找到类型或命名空间“MyType”(或者您是否缺少程序集引用?)”在参考文献中。真正奇怪的是,当我尝试运行该解决方案时,它确实运行没有问题(但我怀疑它会导致其他一些问题)。我尝试重建解决方案,仅重建具有该类型所属命名空间的项目,并且我还尝试了此处提到的所有内容: “您是否缺少程序集引用?”编译错误 - Visual Studio 我不确定发生了什么事。我认为这可能是与 csproj 文件相关的问题,但 csproj 文件看起来不错我猜:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

</Project>

我有点迷失,有谁知道这可能与什么相关?先感谢您!

I've been getting an error "The type or namespace 'MyType' could not be found (or are you missing an assembly reference?)", even though the namespace that 'MyType' lives in is added in the references. What is really weird is that when I try to run the solution, it does run with no problem (however I am suspecting it causes some other issues). I tried rebuilding the solution, rebuilding only the project with the namespace that this type is part of, and I also tried all the stuff mentioned here: "Are you missing an assembly reference?" compile error - Visual Studio
I'm not sure what is going on. I thought it might have been a csproj file related issue, but the csproj file looks fine I guess:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

</Project>

I am a bit lost, does anyone know what this can be related to? Thank you in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不在是我 2025-01-25 08:47:36

就像我在上面的评论中提到的那样,我终于解决了这个问题。
我单击了其中有错误的项目上的“添加参考”,如前所述,我看到了适当的参考。但是,即使我看到它,我还是决定在“参考”窗口中单击“浏览”,然后再次添加。当我浏览需要添加作为参考的CSPROJ文件时,它的名称错误。
所以事情是,不久前,我更改了其中包含“ mytype”的项目的CSPROJ文件的名称。即使该项目在我的文件资源管理器和解决方案资源管理器中都有新名称,但是当我从VS2019中的“参考”窗口浏览时,它的名称错误,所以找不到“ mytype”,因为VS正在寻找一个名称错误但不存在的项目。
希望这会帮助某人

:我注意到并想提及的另一件事是,带有“ mytype”的项目是其他人推动的git改变了,我拉了。但是我注意到更改后,我注意到这个项目具有 +图标,而不是锁图标,当我徘徊在它上时,它说“未决添加”,这意味着,即使我拉了更改,也没有检查此更改在我的尽头。因此,我关闭了VS,将其打开并重新打开。

Like I mentioned in the comment above, I finally resolved the issue.
I clicked "Add Reference" on the project that had errors in it, I saw the appropriate reference, as mentioned before. But even though I saw it I decided to click "Browse" in the references window and add it again. When I browsed to the csproj file that needed to be added as a reference, it had the wrong name.
So the thing is, some time ago I changed the name of the csproj file of the project that had 'MyType' in it. Even though the project had the new name in my File Explorer and Solution Explorer, when I browsed to it from the references window in VS2019, it had the wrong name, so 'MyType' couldn't be found, because VS was looking for a project that had the wrong name and didn't exist anymore.
Hopefully that'll help someone ????

P.S.: Another thing that I've notices and wanted to mention is that the project with 'MyType' was the git changes someone else pushed and I pulled. But I noticed after I pulled the changes, this project had a + icon instead of the lock icon, when I hovered over it, it said "Pending Add", which means, even though I pulled the changes, this change wasn't checked in on my end. So I closed VS, opened it back up and re-pulled.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文