.netpluginsf#assembly-resolutionassembly-binding-redirect

How to achieve assembly binding redirect in a plugin scenario?


I have a plugin P extending and application A (.NET40) that I have no control over.
The P assembly (.NET40) has a shared dependency D (.NET35).

Both P and D depend on FSharp.Core, but different versions:

P is compiled against FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
D is compiled against FSharp.Core, Version=2.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Only FSharp.Core, Version=4.4.0.0 is deployed and I subscribe to AppDomain.AssemblyResolve to load the deployed assemblies.

While I'm testing on my machine where both FSharp.Core versions are installed in the GAC, they both end up being loaded with the plugin.

My understanding is that a binding redirect would be the solution here but how can it be done without access to the app.config?


Solution

  • You could deploy D as a publisher policy assembly.

    The benefit of this approach is that client directories do not need to contain *.config files to redirect to a newer version. Publisher policy allows the publisher of an assembly to install a binary version of a *.config file into the GAC (along with the assembly). This way the CLR will be able to perform the requested redirection at the level of the GAC.

    If you want to bypass the publisher policy for a certain app, you can specify so in the app’s *.config file using the <publisherPolicy> element.

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration> 
        <runtime>
            <assemblyBinding xmlns=“urn:schemas-microsoft-com:asm.v1”> 
                <publisherPolicy apply="no" />
            </assemblyBinding>
        </runtime> 
    </configuration>