类型或命名空间< blah>不存在 [英] The type or namespace <blah> does not exist

查看:203
本文介绍了类型或命名空间< blah>不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我已经有一百万次了,它已经回答了1百万+1次之前。



然而,再次。我有3个项目,A,B和C,每个都是一个DLL。每个项目是.Net 4.0(不是客户端构建,完全4.0)。



在C语言中,我在.cs文件中有两个using语句,它们被引用为项目,并且输出被设置为在本地复制。 :

 使用A; 
使用B;

当我编译时,我得到的投诉是找不到B. B取决于A。



我应该怎么办?我已经删除并重新添加,关闭VS2010,重新打开它,看看.csproj文件。我只是不能得到它。



有人可以给我足够的感觉,我一次学习这个源头!



是的,这可能是在StackOverflow的某个地方,但不是在任何我到目前为止检查的答案。这些术语只是太泛泛而无用,太多的问题,答案是呃,添加一个参考。我过了这一点。



这里是我得到的错误。有三种,但从过去的经验,最后一个是真正的。

 错误130'AWI.WWG.EXPMRI .MriUpload.Data.MriUpload'不包含'Database'的定义,并且没有扩展方法'Database'接受类型'AWI.WWG.EXPMRI.MriUpload.Data.MriUpload'的第一个参数(您缺少一个使用指令或程序集引用?)

错误114'object'不包含< blah>

错误59无法找到类型或命名空间名称'< blah>'(是否缺少using指令或程序集引用?)

Aha我看了警告,而不只是错误,这是我看到的:

 警告69引用的项目..\..\..\..\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ framework\connectors\Partners.Connectors.Base\Partners.Connectors.Base\Partners.Connectors.Base.2010.csproj'不存在。 AWI.WWG.EXPMRI.MriUpload.Objects 

在这种情况下.csproj文件是B 。即使我删除并重新添加项目引用我得到这个。但是感觉就像我越来越近了!



嗯,我刚刚发现了另一个DLL,称为D,其中A引用。当我将它添加到项目时,我开始得到投诉:

  ----------- ----- 
由于错误,无法显示添加引用对话框:

指定的路径,文件名或两者都太长。完全限定文件名必须小于260个字符,目录名必须小于248个字符。
----------------

这是相关的,还是只是另一个分心?






好的,我发现了问题,虽然我不明白。 / p>

当我通过IDE添加引用时,它将其添加到csproj文件中:

 < ProjectReference Include =.. \..\..\..\..\..\..\Partners\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' \connectors\Partners.Connectors.Base\Partners.Connectors.Base\Partners.Connectors.Base.2010.csproj> 

这不编译,它警告它找不到引用的项目,那么所有这些错误发生。但是我将ProjectReference更改为以下内容:

 < ProjectReference Include =C:\ ... \Partners .Connectors.Base.2010.csproj> 

...它工作正常。注意,这些路径都不接近256个字符。完全限定的只有135个字符。但是也许IDE正在做一些愚蠢的路径装饰。

解决方案

解决方案与Windows中的文件路径限制,以及IDE将相对路径转换为完整路径的方式,如此博客中所述



立即解决方法是手动编辑csproj文件以使用绝对路径。在重新添加引用之前,绝对路径将有效。有一天我可以缩短我的文件夹,但这不是当前的首要任务。



如果您怀疑您有这个问题,请查看编译器的警告消息。我经常有这些关闭自己,只看错误。但是关于被引用的项目不存在的警告是为我解决这个问题的线索。



如果其他链接消失,这里是到MS的链接文章。
http://support.microsoft.com/kb/2516078



值得注意的是,对于各种问题,例如客户端框架定位问题,也会出现同样的错误,当引用加载失败时,会将其记录为警告。推测参考错误只是一个警告,因为如果参考实际上不需要它并不重要。


Ok, I have had this one a million times before and it's been answered 1 million +1 times before.

And yet, once again. I have 3 projects, A, B, and C, each a DLL. Each project is .Net 4.0 (not the client build, full 4.0). Project C references A and B. They are referenced as projects, and the output is set to copy locally.

In C, I have two using statements in my .cs file:

using A;
using B;

When I compile, I get the complaint that is cannot find B. A is fine. B depends on A.

What the heck should I do? I've removed and re-added, closed VS2010, re-opened it, looked at the .csproj file. And I just cannot get it. Again, for the millionth time.

Someone please slap enough sense into me that I learn the source of this once and for all!

And yes, this is probably answered somewhere in StackOverflow, but not in any of the top answers I've checked so far. The terms are just too generic to be of use, too many questions where the answer is "duh, add a reference". I'm past that point.

Here are the errors I get. There are 3 kinds, but from past experience, the last one is the true one.

Error   130 'AWI.WWG.EXPMRI.MriUpload.Data.MriUpload' does not contain a definition for 'Database' and no extension method 'Database' accepting a first argument of type 'AWI.WWG.EXPMRI.MriUpload.Data.MriUpload' could be found (are you missing a using directive or an assembly reference?) 

Error   114 'object' does not contain a definition for <blah>

Error   59  The type or namespace name '<blah>' could not be found (are you missing a using directive or an assembly reference?)    

Aha I looked at the warnings, not just the errors, and here is what I see:

Warning 69  The referenced project '..\..\..\..\..\..\..\Partners\integration\framework\connectors\Partners.Connectors.Base\Partners.Connectors.Base\Partners.Connectors.Base.2010.csproj' does not exist.  AWI.WWG.EXPMRI.MriUpload.Objects

That .csproj file is the "B" in this case. Even though I remove and re-add the project reference I get this. But it feels like I'm getting closer!

Hmm, I just found another DLL, call it "D", which "A" references. When I add it to the project, I start to get the complaint:

----------------
The  Add Reference Dialog could not be shown due to the error:

The specified path, file name, or both are too long.  The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
----------------

Could this be related, or just another distraction?


Ok, I found the issue, though I do not understand it.

When I add the reference through the IDE, it adds this to the csproj file of "C":

<ProjectReference Include="..\..\..\..\..\..\..\Partners\integration\framework\connectors\Partners.Connectors.Base\Partners.Connectors.Base\Partners.Connectors.Base.2010.csproj">

This does not compile, it WARNS that it cannot find the referenced project, then all those ERRORs happen. But then I change the ProjectReference to the following:

<ProjectReference Include="C:\...\Partners.Connectors.Base.2010.csproj">

... and it works just fine. Note that neither of those paths are anything close to 256 characters. The fully qualified one is only 135 characters. But perhaps the IDE is doing some silly decoration of the path.

解决方案

The solution has to do with the file path limits in Windows, and they way the IDE translates relative paths into full ones, as explained in this blog.

The immediate solution is to edit the csproj file manually to use the absolute path. Until the reference is re-added, the absolute path will be valid. One day I may shorten my folders, but it's not top priority at the moment.

If you suspect you have this issue, look at the Warning messages from the compiler. I often have these turned off myself, only looking at errors. But the warning about "the referenced project does not exist" was the clue that solved this for me.

In case the other link disappears, here is the link to the MS article. http://support.microsoft.com/kb/2516078

It is worth noting that this same error manifests for a variety of issues such as client-framework-targeting issues, and is logged as a warning when a reference fails to load. Presumably the reference error is only a warning because if the reference is not actually needed it doesn't matter.

这篇关于类型或命名空间&lt; blah&gt;不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆