Thursday, November 25, 2010

This assembly is built by a runtime newer than the currently loaded runtime

I am planning to move to VS2010 and we develop the library and some other group is responsible for the binary. Now, if we want to move to .NET framework 4.0,but the group responsible for binary saw some compatibility issues and they can't move to 4.0.
I thought well, using the side by side feature of 4.0, I could still move, but when I tried that I got the famous exception "This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded."

I followed some of the forums and only thing they had to say that it is not supported. But there is a way you could do that.

For Example, if binary A.exe is built with Target Framework 3.5 and it loads DLL b.dll, which is built with Target Framework 4.0. Now if you try it you will get the following exception "This assembly is built by a runtime newer than the currently loaded runtime". But if you have the access to A.exe.config file, which is application configuration file of A.exe, then you can add following parameters in A.exe.config and it will work even if A.exe is built with Target Framework 3.5.

<startup>
   <supportedRuntime version="v4.0"/>
   <requiredRuntime version="v4.0"/>
 startup>

Let me know, if you need the source code as an example for the same.