What does .NET mean by ‘primary’ when choosing between conflict dll reference?

You are asking MSBuild to solve a DLL Hell problem. It must copy Microsoft.Practices.EnterpriseLibrary.Common.dll to your build output directory so you can run your program. But you reference two different versions of it. That cannot work, one will overwrite the other and its a crap-shoot who will win.

So it needs to guess which one is more “important”. One of your assemblies has a “primary” dependency, it directly references types inside Microsoft.Practices.EnterpriseLibrary.Common.dll. Another one of your assemblies has a indirect dependency, it uses an assembly that was built with version of asssembly. Forced to guess, MSBuild assumes that the primary one is more important.

It is just a guess. It might work, you need a <BindingRedirect> in the app.exe.config file to map the request for the version of the assembly to the 5.0.505.0 version since the version will not be available. Having a major version mismatch is never good news, a TypeLoadException or MissingMethodException at runtime should not surprise you. If that doesn’t work then installing these assemblies in the GAC might be a workaround, no need to copy the DLLs that way. Of course the real fix is to only ever have one specific dependency.

Leave a Comment