Karthik
Karthik

Reputation: 41

Assembly re-direction in .NET

I have C#.net exe to which i add reference to third party dll's.

These third party dll's are strong named assemblies registered in GAC.

I compile my program with third party dll's(say version 7.0).

When i try to register my C#.net exe program in a machine which has the third party dll'S(say version anything above 7.0) registered in GAC.

If fails randomly in few machine machines stating "Unable to find the assembly version 7.0 Type not registered" again when i recompile my C# project with the dll version present in the target machine it runs successfuly..

Note: a. Let's say project is originally compiled with assembly version 7.0.4.82 & tried to run in 11.0.367.0. b. Test.Framework, Test.Core are the assemblies referenced.

Steps taken to resolve:

Tried assembly re-direction technique with the following app.config file.

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" >

  <dependentAssembly>

    <assemblyIdentity

            name="Test.Framework"

            publicKeyToken="ebf6b2ff4d0a08aa" culture ="neutral"/>

    <bindingRedirect oldVersion="7.0.4.82"

                         newVersion="11.0.367.0" />

    <publisherPolicy apply="no" />

  </dependentAssembly>

  <dependentAssembly>

    <assemblyIdentity

            name="Test.Core"

            publicKeyToken="ebf6b2ff4d0a08aa" culture ="neutral"/>

    <bindingRedirect oldVersion="7.0.4.82"

                         newVersion="11.0.367.0" />

    <publisherPolicy apply="no" />

  </dependentAssembly>     


</assemblyBinding>

Please suggest me some steps to resolve this.

Thanks in Advance.

Upvotes: 1

Views: 229

Answers (2)

MarkJ
MarkJ

Reputation: 30408

Why don't you just distribute the versions you need with your application? Create an installation (deployment) that registers the versions you need in the GAC. The DLL vendor may provide a merge module you can just drop into your installation.

Alternatively just use local copies of the DLL as suggested by Igor.

Upvotes: 0

Igor Brejc
Igor Brejc

Reputation: 19004

My suggestions:

  1. Turn on the Fusion logging (see here)
  2. Do not rely on assemblies installed in GAC. Instead of referencing them in your VS project from GAC, add them to your source code repository in a separate directory and then reference from there. This way you have the control over which version of 3rd party assemblies your app is using. See how we did it here.

Upvotes: 4

Related Questions