Kovalev Roman
Kovalev Roman

Reputation: 51

.Net trouble of reference to difference version of library

I have F#(C# I think the same) project A that have reference to QuickGraph library of version 3.4. A used in project B that have reference to modern QuickGraph 3.6. In app.config of B:

 <runtime>
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="QuickGraph" publicKeyToken="f3fb40175eec2af3" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.6.61114.0" newVersion="3.6.61114.0" />
      </dependentAssembly>
    </assemblyBinding>    
 </runtime>

Its works. Anouther project C load in runtime B. When called some methods of A I received an IO error: cannot load version 3.4 of QuickGraph library.

Project C isn't my project and I can't recompile this. What I can do to avoid this error? Thanks!

Upvotes: 2

Views: 76

Answers (1)

Muris
Muris

Reputation: 158

The problem is called "Dependency Hell".

Solution from MSDN:

If you have multiple versions of an assembly in a directory and you want to reference a particular version of that assembly, you must use the element instead of the privatePath attribute of the element. If you use the element, the runtime stops probing the first time it finds an assembly that matches the simple assembly name referenced, whether it is a correct match or not. If it is a correct match, that assembly is used. If it is not a correct match, probing stops and binding fails.

Or you could use AppDomain.AssemblyResolve Event to resolve the assembly to be used.

Upvotes: 2

Related Questions