Mixed mode assembly is built against version v2.0.50727 Error on TFS Build Server
Friday, January 7, 2011
Today I made what should have been a easy change to some code I was working. I needed to embed a file as a resource in my application, and then at runtime, retrieve that file using reflection. Everything was working fine until I checked my code in and let the Continuous integration process kick in. I ended up with a failed build due to unit tests not passing and a lovely error message:
Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.
Bing brought back several hits but most of them dealt with changing the setting in IIS. I finally found a good explanation of what was going on from this stack overflow question: http://stackoverflow.com/questions/1604663/what-does-uselegacyv2runtimeactivationpolicy-do-in-the-net-4-config. The problem that most people have with this issue, is that they do not know what .config file to add the ‘useLegacyV2RuntimeActivationPolicy’ setting to. Since the error was happening during the execution of my unit tests, I figured that I needed to add this to my xunit.console.exe.config file.
<requiredRuntime version="v4.0.20506" safemode="true"/
The required runtime was in my configuration file previously, the supportedRuntime element, and useLegacyV2RuntimeActivationPolicy attribute was added to fix my problem. I should note, that I did not encounter the ‘Mixed mode assembly’ error on my 32bit build server.