开发者

How to link a .NET 2.0 assembly in a .NET 4.0 solution

开发者 https://www.devze.com 2023-01-12 00:48 出处:网络
I have a project built with .NET 4.0. I have a lot of code that would be painful to convert back to 2.0.

I have a project built with .NET 4.0. I have a lot of code that would be painful to convert back to 2.0.

I try to import a Dll built with .NET 2.0. Everything works until I try to execute code from that DLL. It says that it cannot load the specified module or one of its dependency

I used dumpbin.exe to check what dependencies it can have

File Type: DLL

  Section contains the following imports:

    mscoree.dll
                402000 Import Address Table
                4057F0 Import Name Table
                     0 time date stamp
                     0 Index of first forwarder reference

                    0 _CorDllMain

So my guess here is that the dll tries to load, but cannot find mscoree.dll from version 2.0 and开发者_开发知识库 thus raises an Exception.

I tried to load my target module manually with

Assembly asm = Assembly.LoadFrom(dllPath);

Visual Studio debugger now list the module as loaded, but still it cannot access it. Windows search reports dozens of "mscoree.dll" scattered everywhere in the c:\windows directory so I'm a little sceptical about loading it manually.


You are not close to diagnosing the problem. Dumpbin.exe doesn't show you anything that it wouldn't show for any managed assembly. Nor is this a problem that's specific to mixing CLR dependencies.

Use fuslogvw.exe to find out what dependency is missing.


  1. Start by finding all of its dependencies. The fact that you haven't listed them here is troubling.
  2. Have you application directly reference all of said dependencies.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号