Question

Context

I have 2 different versions of an assembly installed in GAC, version 1.0 and version 2.0. I made an application that is referencing 1.0 as a specific version.

Issue

When I run my application, it will always load version 2.0 whereas the application is specifically referencing version 1.0.

Question

Why is this happening? How can I force my application to load the version it has been compiled for?

It does not seem to me that this has anything to do with a binding redirect as my application was not even aware of version 2.0 when I built it and that the reference "Specific Version" metadata is set to true.

Thanks.


Edit:

The assembly I am referencing is actually Oracle.DataAccess from the ODAC package. I noticed that other assemblies named Policy.x.xxx.Oracle.DataAccess where published in GAC.


Edit 2:

After looking into the Oracle.DataAccess policy I found the configuration defining the binding redirect:

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89B483F429C47342"/>
            <bindingRedirect oldVersion="4.112.0.0-4.112.3.0" newVersion="4.112.3.0"/>
        </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>

Even though I added the reversed binding redirect into my application configuration, the policy in GAC seems to have the priority. I found an MSDN article treating the subject and suggesting to ignore policy with this configuration:

<publisherPolicy apply="no" />

But it still does not work...


Edit 3:

I tried to remove the policy from the GAC and rebooted my machine. It finally worked. It does not feel like a confortable solution development but this policy does broke one of my application which means disabling the policy is the right thing to do in my case.


Final Edit:

Igor gave me the right answer. All I had to do to workaround those policies was to use the publisherPolicy setting in the right configruation section:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89B483F429C47342"/>
      <publisherPolicy apply="no"/>
    </dependentAssembly>
  </assemblyBinding>
</runtime>
Was it helpful?

Solution

After you have edited your question it becomes clear that this is the policy file which affects assembly binding.

In case of Oracle there's a file called Policy.X.Y.Oracle.DataAccess.config with the contents similar to this:

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89B483F429C47342"/>
            <bindingRedirect oldVersion="10.1.0.000-10.2.0.100" newVersion="10.2.0.100"/>
        </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>

The policy is installed by the Oracle Installer and redirects Oracle.DataAccess.dll to the latest version, as Oracle believes the library is backward compatible.

EDIT: If you don't want publisher policy to be applied for a particular assembly, put the element in the element:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
        <assemblyIdentity name="myAssembly" publicKeyToken="..."  culture="en-us" />
        <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
            <publisherPolicy apply="no" />
    </dependentAssembly>
</assemblyBinding>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top