3

I am using Oracle.DataAccess, and need to access an older database, which means I need to use a bit older version of this assembly. Both the new and old assemblies are in the GAC, but I cannot seem to get the application to use the older version. Here is my .config file:

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

fuslogvw shows nothing (as in nothing, completely empty), but I am not too familiar with this tool, so maybe I'm using that wrong (too).

Any ideas?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
jjespersen
  • 49
  • 5
  • Did you [do this](https://stackoverflow.com/questions/255669/how-to-enable-assembly-bind-failure-logging-fusion-in-net)? – John Wu Mar 12 '18 at 10:26
  • Are you sure your version numbers are right? The old version number `2.121.1.0` looks newer than the new version number `2.112.3.0` – Lithium Mar 12 '18 at 10:44
  • But is that not how it's supposed to be? If I have v2 and v1 of a .dll, but want to bind to v1 as opposed to the default v2, then I set oldVersion=v2 and newVersion=v1 to tell my application to use v1? – jjespersen Mar 12 '18 at 11:06

2 Answers2

1

Your config file looks right. But I would change the old version to this 0.0.0.0-2.999.9.0. Because then you don't really care what the actual version of the Oracle dll is and new version is the correct (Old) version you want to work with.

Now are you sure this is the correct version? The version 2 of Oracle.DataAccess is frightfully old.

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

And here is some more info from MS https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/bindingredirect-element

Archlight
  • 2,019
  • 2
  • 21
  • 34
0

I need to use a bit older version of this assembly.

That is not what assembly redirects are for. The purpose of assembly binding redirects is so you can use a newer version of an assembly that is a dependency of an assembly that was compiled against an older version.

For example, your application depends on LibraryX and LibraryX depends on LibraryY version 1.0.

YourApp -> LibraryX (v3.2) -> LibraryY (v1.0)

For the sake of argument, your application needs to use version 2.0 of LibraryY directly.

YourApp -> LibraryX (v3.2) -> LibraryY (v1.0)
        -> LibraryY (v2.0)

This won't work because your application is using a newer version of LibraryY than LibraryX was when it was compiled.

So, we add a binding redirect to force LibraryX to use the same version as YourApp.

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="LibraryY" publicKeyToken="89b483f429c4fecd"/>
        <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Which changes it to:

YourApp -> LibraryX (v3.2) -> LibraryY (v2.0)
        -> LibraryY (v2.0)

Your Case

If you want to use an older version of the assembly in your application, then you need to reference the older version in your application. This problem cannot be solved using binding redirects, only by using a direct assembly reference to the specific version of Oracle.DataAccess your application needs to use.

In your application's .csproj file:

<ItemGroup>
    <Reference Include="Oracle.DataAccess, Version=2.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86">
        <SpecificVersion>True</SpecificVersion>
        <HintPath>C:\Windows\assembly\GAC_32\Oracle.DataAccess\2.121.1.0__89b483f429c47342\Oracle.DataAccess.dll</HintPath>
    </Reference>
<ItemGroup>

Note that I am not sure about whether Oracle.DataAccess is an x86 or x64 GAC reference, so if the latter you may need to change both the processorArchitecture and HintPath above to match.

Reference: Redirecting Assembly Versions

NightOwl888
  • 55,572
  • 24
  • 139
  • 212
  • According to the Microsoft documentation it states that newVersion can be an earlier version? – Archlight Mar 12 '18 at 13:12
  • 1
    Apparently so. See [Redirecting Assembly Versions](https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/redirect-assembly-versions#relying-on-automatic-binding-redirection). But it is better just to compile against the old version if you can. – NightOwl888 Mar 12 '18 at 13:13