9

So, I have a 3rd party .dll written in C# 2.0 that needs to be strongly typed and I do not have access to the source code. I found several articles on how to disassembly the .dll and re-assembly it with a strongly named key file.

Problem I am having is that VS2010 recompiles it as a .NET 4.0 .dll instead of a 2.0 .dll (the version our application is currently in). I can't include the "new" dll in my project because it gives me a runtime error of: "This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded." If I don't sign the dll, I get the "assembly is not strongly typed." error.

Is there a way to recompile this .dll in the 2.0 framework using VS2010 ilasm.exe?

Sean
  • 2,496
  • 7
  • 32
  • 60

2 Answers2

14

You are probably using the Visual Studio 2010 Command Prompt. It will setup the environment to run C:\Windows\Microsoft.NET\Framework\v4.0.30319\ilasm.exe when you type "ilasm.exe". Wrong version, you want v2.0.50727\ilasm.exe. Type the full name. Or copy and edit vc\bin\vsvarsall.bat

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
1

No, you cannot use the 4.0 ilasm to compile to 2.0; you should be using the ilasm.exe from the 2.0 framework directory; for example C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727.

Note that all you should need for this is the runtime, not the SDK or VS 2005 / 2008.

vcsjones
  • 138,677
  • 31
  • 291
  • 286