本文翻译自:The type or namespace name could not be found [duplicate]
This question already has an answer here: 这个问题在这里已有答案:
I have a C#
solution with several projects in Visual Studio 2010
. 我有一个C#
解决方案,在Visual Studio 2010
有几个项目。 One is a test project (I'll call it " PrjTest "), the other is a Windows Forms Application
project (I'll call it " PrjForm "). 一个是测试项目(我将其称为“ PrjTest ”),另一个是Windows Forms Application
项目(我称之为“ PrjForm ”)。 There is also a third project referenced by PrjForm, which it is able to reference and use successfully. 还有一个由PrjForm引用的第三个项目,它能够成功引用和使用。
PrjForm references PrjTest , and PrjForm has a class with a using
statement: PrjForm引用PrjTest , PrjForm有一个带有using
语句的类:
using PrjTest;
- Reference has been correctly added 参考已正确添加
-
using
statement is correctly in placeusing
语句正确到位 - Spelling is correct 拼写是正确的
- PrjTest builds successfully PrjTest构建成功
- PrjForm almost builds, but breaks on the
using PrjTest;
PrjForm几乎构建,但打破了using PrjTest;
line with the error: 与错误一致:
The type or namespace name 'PrjTest' could not be found (are you missing a using directive or an assembly reference?) 找不到类型或命名空间名称'PrjTest'(您是否缺少using指令或程序集引用?)
I've tried the following to resolve this: 我尝试过以下方法来解决这个问题:
- Removed Resharper (since Resharper had no trouble recognizing the referenced project, I thought it might be worth a shot) 删除了Resharper(因为Resharper在识别引用的项目时没有遇到任何麻烦,我认为它可能值得一试)
- Removed and re-added the reference and using statement 删除并重新添加了引用和using语句
- Recreated PrjForm from scratch 从头开始重新创建PrjForm
- PrjForm currently resides inside the PrjTest folder, I tried moving it to an outside folder PrjForm目前驻留在PrjTest文件夹中,我尝试将其移动到外部文件夹
- Loaded the solution on a different computer with a fresh copy of
VS 2010
使用VS 2010
的新副本在另一台计算机上加载解决方案
I have done my homework and spent far too long looking for an answer online, none of the solutions has helped yet. 我做完了我的功课,花了很长时间在线寻找答案,但没有一个解决方案有帮助。
What else could I try? 我还能尝试什么?
#1楼
参考:https://stackoom.com/question/JzaU/找不到类型或命名空间名称-重复
#2楼
just changed Application's target framework to ".Net Framework 4". 刚刚将Application的目标框架更改为“.Net Framework 4”。
And error got Disappeared. 错误消失了。
good luck; 祝好运; :D :d
#3楼
I had the same issue. 我遇到过同样的问题。 The target frameworks were fine for me. 目标框架对我来说很好。 Still it was not working. 它仍然无法正常工作。 I installed VS2010 sp1, and did a "Rebuild" on the PrjTest. 我安装了VS2010 sp1,并在PrjTest上进行了“Rebuild”。 Then it started working for me. 然后它开始为我工作。
#4楼
Changing the framework to 将框架更改为
.NET Framework 4 Client Profile
did the job for me. 为我做了这份工作。
#5楼
For COM/ActiveX references, VS 2012 will show this error right on using statement. 对于COM / ActiveX引用,VS 2012将在using语句上显示此错误。 Which is quite funny, since it's saying that may be you are missing a using statement. 这很有趣,因为它说你可能错过了一个使用声明。
To solve this: register the actual COM/ActiveX dll even if it's in the neighbor project, and add a reference through COM channel, not project channel. 要解决此问题:即使它位于邻居项目中,也要注册实际的COM / ActiveX dll,并通过COM通道而不是项目通道添加引用。 It will add Interop.ProjectName instead of ProjectName as a reference and this solves this strange bug. 它将添加Interop.ProjectName而不是ProjectName作为参考,这解决了这个奇怪的错误。
#6楼
In my case I had: 在我的情况下,我有:
Referenced DLL : .NET 4.5
引用的DLL: .NET 4.5
Project : .NET 4.0
项目: .NET 4.0
Because of the above mismatch, the 4.0 project couldn't see inside the namespace of the 4.5 .DLL. 由于上述不匹配,4.0项目无法在4.5 .DLL的命名空间内看到。 I recompiled the .DLL to target .NET 4.0 and I was fine. 我重新编译.DLL以目标.NET 4.0,我很好。