0

I have a question regarding the 2 CLR versions, i.e. version 2 and version 4 of the .NET framework, which use different GAC locations. I have a client application built which references an assembly “X” from the v2 GAC (C:\Windows\Assembly). I am now updating the assembly “X” to run on v4 of the .NET framework (C:\Windows\Microsoft.NET\assembly), however, I do not want to recompile the client application. Note, assembly "X" is removed from the v2 GAC before installing the to v4 GAC.

Is it possible to create a publisher policy file which redirects an assembly which used to reside in version 2 of the CLR to version 4 of the CLR? If so, how is this achieved?

I have searched the MSDN, and understand there is an appliesTo field on the assemblyBinding element where you can specify the version of the .NET framework, but this seems to encompass the whole bind.

What I would like is something like:

<bindingRedirect oldVersion="1.0.0.0" .Net 2 newVersion="2.0.0.0" .Net 4/>

I have read here http://msdn.microsoft.com/en-us/magazine/dd727509.aspx that CLR v2.0 applications now cannot see CLR v4.0 assemblies in the GAC. However, you can force an app to use the updated CLR using:

<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />

So would a mixture of this plus the publisher policy suffice, or is there another way?

Jeb
  • 3,689
  • 5
  • 28
  • 45

1 Answers1

1

The determining factor here is which version of the CLR your client app is running under. If it's v2 then there's nothing you can do in order to make v4 assemblies usable or even visible to it. If it does run under the v4 CLR then it would automatically try to resolve assembly references in the v4 GAC first.

The good news is, there is not need for you to recompile your client app in order to achieve that. You can simply force it to run under .Net 4 by adding this to the app's config file:

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

This should give you what you wanted.

mthierba
  • 5,587
  • 1
  • 27
  • 29
  • Thanks; We have clients in the field which were built interfacing the assembly in the GAC, so when we release a new version of the assembly (by replacing, not adding), we don't want to force them to recompile against the new version - hence why we use publisher policy assemblies for the redirection. It's good that we can avoid recompilation of the client app; however, this means we now need to ensure the client has an app.config, and remember to update these to support the v4 runtime when we release the new assembly as you described. It would be nice if publisher policy could cope with this! – Jeb Aug 03 '11 at 14:59
  • There's a registry setting via which you can force all apps to run under the most recent CLR. See this answer: http://stackoverflow.com/questions/2094694/launch-powershell-under-net-4/2096906#2096906. Don't know if that's feasible at all for you, but it would certainly remove the need to have an App.config in place for each client (provided you can automate making the registry settings via a GPO or similar, of course!). – mthierba Aug 03 '11 at 16:25