8

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>
4
  • Did you check that there was no publisher policy for your referenced assembly? Commented May 22, 2012 at 11:23
  • @IgorKorkhov: Yes I found something called Policy.x.xxx.MyAssemblyName in the GAC. I was not aware of such a mechanism. I edit my question and you can submit a reply. Thanks.
    – Ucodia
    Commented May 22, 2012 at 11:44
  • Tangential question: What is the problem that makes you want to use V1? I use Oracle occasionally, so forewarned is forearmed :)
    – Ian
    Commented May 22, 2012 at 12:25
  • @Ian: The application was built with version 1.0 and version 2.0 breaks the applicaton.
    – Ucodia
    Commented May 22, 2012 at 12:29

1 Answer 1

7

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>
6
  • I tried with <bindingRedirect oldVersion="4.112.3.0" newVersion="4.112.1.2"/> but it did not resolved the issue. I read here that I could use <publisherPolicy apply="no" /> to ignore policies but still the same issue...
    – Ucodia
    Commented May 22, 2012 at 12:05
  • @Ucodia: that's strange. Are you referencing v4.112.3.0 in your app? Maybe you should try including a range of versions (say, 0.0.0.0-4.65535.65535.65535) to see if this will work? Commented May 22, 2012 at 12:17
  • I specifically reference 4.112.2.1. I updated my question with some new findings. It looks like the policy published in GAC overrides any application configuration.
    – Ucodia
    Commented May 22, 2012 at 12:22
  • @Ucodia: indeed, the policy does override application configuration, but <publisherPolicy apply="no" /> inside <assemblyIdentity /> should still work. Commented May 22, 2012 at 13:06
  • It worked with policy enabled! I was actually defining this setting in the wrong configuration section, thus the setting was not used. Thank you very much for your valuable help. You should update your answer then :)
    – Ucodia
    Commented May 22, 2012 at 13:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.