Andrei Smolin

Loading a .NET 2.0 Office add-in on a machine with .NET 4.0

The fact is: almost all Office add-ins will load correctly in this situation. Yes, you don’t need to modify anything in the add-in unless your add-in is affected by the issues described in .NET Framework 4 Migration Issues.

Another scenario requiring your attention is when your add-in uses mixed-mode assemblies. In this case, you may get this exception:

“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.”

The exception occurs because .NET 4.0 has changed the way it binds to older mixed-mode assemblies.

In this case, you’ll need to modify the setup project.

First off, set the /useLegacyV2RuntimeActivationPolicy=true parameter of adxregistrator.exe utility, see the custom actions of your setup project.

Also you might be required to add the useLegacyV2RuntimeActivationPolicy element to the configuration file of the host application. The element is described here. An example of its use is as follows:

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

To modify the .config file of the host application – do you remember that we talk about using mixed-mode assemblies in your add-in? – look into the Office folder. Say, for an add-in targeting Excel, the file name is excel.exe.config, for PowerPoint – powerpnt.exe.config, etc. Create or modify this file, whichever applies, but be aware that this requires administrative privileges.

Good luck!

Post a comment

Have any questions? Ask us right now!