Its all just words!

Whilst migrating an existing framework version 2 application to version 4.5 of the .NET framework i came up against the following mixture of words for an error message that to be honest made me just blank over at the descriptiveness of it all.

Mixed mode assembly is built against version ‘v2.0.50727′ of the runtime and cannot be loaded in the 4.0 run-time without additional configuration information.

It is both self-explanatory and in turn just a bunch of words that makes you head for the nearest bar to consider why you ever bothered to learn to read at all. Once my eyes came back into focus again I googled this message and found that the solution was actually quite simple. Now it might just be me being lazy but I would have thought that at compile time Visual Studio would have alerted to me to this issue (as I’m sure the run-time must have known) and asked if it should automagically fix this issue. It didn’t so I’m forced to blog so that I don’t forget the next time this never happens!

OK. So as I said, a very simple fix. To the config of my migrated 4.5 application we simply add the following lines (or change them if they are already there in some manner). The critical line here is ‘useLegacyV2RuntimeActivationPolicy‘ which tells the runtime loading process that version 2 runtime activation is supported. This ‘hack’ is because back in the day when 2.0 was fresh and clean and sparkling Microsoft had never really identified that this was ever going to be an issue. So hence years later we need to ‘Jemmy’ in a workaround.

<?xml version="1.0" encoding="utf-8"?>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>

Note that legacy apps in the future, say version 4 upgrading to version 6 or 7 will not require this as multiple version of the CLR are now supported completely and from the ground up.For a much fuller digression into the background of this article please see this excellent and in-depth article here.

I hope this helps.