visual-studio 引用的程序集不会加载
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2655763/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Referenced Assembly won't load
提问by Pavel
I've got a visual studio 2010 project which publishes an assembly called myAssembly.ddl.
I then want to reference myAssembly.dllfrom an existing vs 2008 project. If I try to load the reference it comes up with an yellow exclamation mark next to it, suggesting that the assembly wasn't loaded. However, I'm not getting any error messages during that process. Obviously, if i try to import the namespace in my code it doesn't compile.
我有一个 Visual Studio 2010 项目,它发布了一个名为myAssembly.ddl. 然后我想myAssembly.dll从现有的 vs 2008 项目中引用。如果我尝试加载引用,它旁边会出现一个黄色感叹号,表明未加载程序集。但是,在此过程中我没有收到任何错误消息。显然,如果我尝试在我的代码中导入命名空间,它不会编译。
Converting myAssembly.dllto a .net version 3.5 doesn help.
Nor does copying the assembly to a different directory and referencing it from there.
转换myAssembly.dll为 .net 3.5 版没有帮助。也不会将程序集复制到不同的目录并从那里引用它。
Any ideas?
有任何想法吗?
回答by Robert Williams
Which .NET Framework are you using to build the solution in Visual Studio 2008?
您使用哪个 .NET Framework 在 Visual Studio 2008 中构建解决方案?
It needs to be version 3.5 in order to allow you to utilize the myAssembly.dll that you compiled with the 3.5 framework. Visual Studio 2008 will allow you to target the 2.0 Framework or even the 3.0 Framework.
它需要是 3.5 版,以便您可以使用使用 3.5 框架编译的 myAssembly.dll。Visual Studio 2008 将允许您以 2.0 框架甚至 3.0 框架为目标。
Visual Studio 2008
视觉工作室 2008
Project > Properties > Application tab Look for Target Framework
项目 > 属性 > 应用程序选项卡查找目标框架
回答by Hans Passant
I get a repro for this. It is visible in Ildasm.exe, the 2010 compiler marks the metadata as v4.0.30319. You can also see it with Corflags.exe. The 2008 build system generates a warning for this, you can see it in the Output window:
我得到了一个复制品。它在 Ildasm.exe 中可见,2010 编译器将元数据标记为 v4.0.30319。您也可以使用 Corflags.exe 来查看它。2008 构建系统为此生成警告,您可以在输出窗口中看到它:
warning MSB3246: Resolved file has a bad image, no metadata, or is otherwise inaccessible
警告 MSB3246:已解析的文件包含错误图像、没有元数据或无法访问
Changing the Target Framework to 3.5 fixes the problem, the assembly will now be marked as v2.0.50727, the CLR version used in 2005 and 2008. The IDE is however not smart enough to detect this change. You'll have to remove the assembly reference, then put it back in. And the yellow exclamation mark is no longer there.
将目标框架更改为 3.5 修复了该问题,程序集现在将标记为 v2.0.50727,即 2005 和 2008 中使用的 CLR 版本。但是,IDE 不够智能,无法检测到此更改。您必须删除程序集引用,然后将其放回原处。黄色感叹号不再存在。

