how to integrate .net library (.dll) from higher version with binaries from lower version

霸气de小男生 提交于 2019-12-28 06:53:18

问题


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.



来源:https://stackoverflow.com/questions/4377219/how-to-integrate-net-library-dll-from-higher-version-with-binaries-from-lowe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!