I have external .net library compiled with .net framework 4 (it's provider moved recently to .net 4) My code currently runs on .net framework 3.5 How to use that external library in my application ? Moving whole application to .net 4 needs time and testing, so maybe in a future i will do that, but now, what are the possibilities ?
问题:
回答1:
There are no possibilities, the CLR version that comes with .NET 3.5 cannot load 4.0 assemblies. The metadata format was changed. You have to force your app to use the .NET 4.0 CLR version. Do so by recompiling it with VS2010, targeting 4.0, or by using a .config file that contains the <requestedRuntime>
element to ask for "v4.0".
Compatibility for .NET 4.0 is excellent btw.
回答2:
While you cannot load the .Net DLL directly, you can wrap it in a COM interface, and load that COM interface in your .Net 3.5 process.
See Using a .NET 4 Based DLL From a .NET 2 Based Application
For more background information, Microsoft originally added In-Process Side-by-Side in .Net 4 to better support the scenario where an application loads add-ins via COM, and the add-ins were written with various versions of .Net. The ability to load .Net 4 DLLs in a .Net 3.5 process is just a nice side effect of that.