Referenced Assembly won't load

2019-08-29 17:57发布

I've got a visual studio 2010 project which publishes an assembly called myAssembly.ddl. I then want to reference myAssembly.dll from 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.

Converting myAssembly.dll to a .net version 3.5 doesn help. Nor does copying the assembly to a different directory and referencing it from there.

Any ideas?

2条回答
Lonely孤独者°
2楼-- · 2019-08-29 18:22

Which .NET Framework are you using to build the solution in 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.

Visual Studio 2008

Project > Properties > Application tab Look for Target Framework

查看更多
你好瞎i
3楼-- · 2019-08-29 18:44

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:

warning MSB3246: Resolved file has a bad image, no metadata, or is otherwise inaccessible

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.

查看更多
登录 后发表回答