COM Servers built for .NET 2.0 running on Windows8 without .NET 2.0 being used



COM Servers built for .NET 2.0 running on .NET 4.0 without .NET 2.0 being used.
Scenario:-
·         An application had .Net 2.0 or 3.5 dll assemblies which needed to be consumed by unmanaged COM clients.
·         And application unmanaged binaries also uses the assemblies in javascript executed in embedded web control.
·         And those binaries needed to be executed on Windows 7 , Windows 8 and older versions of windows (XP) as well.
·         Product installer needs to run RegAsm.exe to register the assemblies as COM components and when application is launched should not be prompted to install .NET 2.0 or 3.5
·         In Windows 8, user will be prompted to download .Net framework version 2.0 or 3.5, since by default only 4.0 will be installed and 3.5 is not enabled by default. We had a constraint of not redistributing and installer needs to be a silent installation. Other constraint is to achieve this without any code changes.
 

Solution that Worked
For all the exes that are supposed to load the .NET assemblies, created an <application-name>.exe.config file, to tell the CLR that we are aware that COM server was built for an earlier version of the CLR and it is okay to run it with the version 4 CLR. By that we prevented the version 2 CLR from being used.

 
<application-name>.exe.config file would be like this
<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4"/>
        <supportedRuntime version="v2.0.50727"/>
    </startup>
</configuration>

References:-
http://msdn.microsoft.com/en-us/library/jj152935.aspx

No comments:

Post a Comment