P.K.
P.K.

Reputation: 1772

How to use GAC assembly with specific version in C# app

I have 2 GAC assemblies called AAA (version 1.0.0.0 and version 2.0.0.0). The application currently is using version 1 (reference added by Browse-for-assembly, path is hardcoded to this file), but I want to use version 2.

To do it smoothly, I added some code to app.config:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="AAA"
          publicKeyToken="dd8b40231cb0196b"
          culture="en-us" />
        <!-- Assembly versions can be redirected in app, 
          publisher policy, or machine configuration files. -->
        <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

But application still is using version 1.0.0.0 of assembly, why?

Upvotes: 1

Views: 473

Answers (1)

Hans Passant
Hans Passant

Reputation: 941218

      culture="en-us" />

That's wrong, assemblies that contain code are always neutral. Only satellite assemblies have culture. Or in other words, your bindingRedirect doesn't match any of the assemblies that the app is asking for. So has no effect. Be sure to delete the assembly from the project's bin\Debug directory so you can diagnose mistakes like this. The Fuslogvw.exe utility is also very handy, log all binds.

Fix:

      culture="neutral" />

Upvotes: 2

Related Questions