The personal ramblings of Jon Carlos mobile & web developer and technology enthusiast.

Tuesday, 28 August 2012

Could not load file or assembly. The located assembly's manifest definition does not match the assembly reference.

13:53 Posted by Jon Carlos No comments
Ran in to an issue today where I had installed 2 packages from nuget which both referenced Newtonsoft.Json but completely different versions.

I put a call out on Twitter and got some great sugestions from @joeriks and @ismailmayat who suggested adding the dependentAssembly tag to my web.config to allow me to run multiple versions of the same DLL.

I work on this for a couple of hours but could not get it working. The project is a nopcommerce project and as it uses a plugin architecture the dlls are not in the bin directory but in a plugins directory. I think one of the reasons I had so much trouble was already a version of Newtonsoft.Json in the bin folder for the core project as well. So no matter what I did I could not reference the correct DLL.

This led me to Google a bit further and find ILMerge, now I remember Matt Brailsford taking about this a while so I checked out his blog and but he was using build events and I did not need this to run multiple times just once so Googled a bit further downloaded ILMerge and started to bundle the packages I had downloaded from nuget.

Once ILMerge is installed open up the command prompt and navigate to your install directory. Once there all you need to do if run the following command and it'll bundle all your dlls in to one.

ilmerge /out:"createsend-dotnet.merged.dll" "createsend-dotnet.dll" "Newtonsoft.Json.dll" /targetplatform:v4,"C:\Windows\Microsoft.NET\Framework\v4.0.30319"

That example is for Campaign Monitors API package remember you may need to add the full directory locations of your dlls, i've stripped them here to make it easuer to read. but the basic break down is like this.

/out:"NEW-NAME-FOR-YOUR.dll"

"PRIMARY.dll"

"SECONDARY.dll" You can have as many of these as you like you just add more to the list

 /targetplatform:THE-.NET-VERSION,"THE-PATH-TO-YOUR-.NET-FRAMEWORK-DIRECTORY"

Hope this helps for future reference :)

0 comments: