Friday, February 04, 2011

AsmSpy: A little tool to help fix assembly version conflicts

Do you ever get these kinds of messages when you compile your project?

------ Build started: Project: Suteki.Shop.CreateDb, Configuration: Debug x86 ------
No way to resolve conflict between "System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
and "System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35".
Choosing "System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" arbitrarily.
Consider app.config remapping of assembly "NHibernate, Culture=neutral, PublicKeyToken=aa95f207798dfdb4"
from Version "" [] to Version ""
[D:\Source\sutekishop\Suteki.Shop\packages\NHibernate.\lib\NHibernate.dll] to solve conflict and get rid of warning.
Consider app.config remapping of assembly "System.Web.Mvc, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
from Version "" [C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 2\Assemblies\System.Web.Mvc.dll] to Version ""
[C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll] to solve conflict and get rid of warning.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3247:
Found conflicts between different versions of the same dependent assembly.
Suteki.Shop.CreateDb -> D:\Source\sutekishop\Suteki.Shop\Suteki.Shop.CreateDb\bin\Debug\Suteki.Shop.CreateDb.exe

The problem is that the build output doesn’t tell me which of my assemblies references version of System.Web.Mvc and which references version

If you’re writing software using lots of 3rd party assemblies like I do, it’s a constant problem. I’ve written a little bit of code that I drag around with me that outputs lists of assemblies that my assemblies reference. I’ve found it very useful for resolving these kinds of issues.

Now I’ve wrapped it up as a little console app, AsmSpy, and put it on github here:

Or you can download a zip file of the compiled tool here:

How it works:
Simply run AsmSpy giving it a path to your bin directory (the folder where your project's assemblies live). E.g:

AsmSpy D:\Source\sutekishop\Suteki.Shop\Suteki.Shop\bin

It will output a list of all the assemblies referenced by your assemblies. You can look at the
list to determine where versioining conflicts occur.
The output looks something like this:

Reference: System.Runtime.Serialization by Microsoft.ServiceModel.Samples.XmlRpc by Microsoft.Web.Mvc by Suteki.Shop
Reference: System.Web.Mvc by Microsoft.Web.Mvc by MvcContrib by MvcContrib.FluentHtml by Suteki.Common by Suteki.Common by Suteki.Shop by Suteki.Shop
Reference: System.ServiceModel.Web by Microsoft.Web.Mvc
Reference: System.Web.Abstractions by Microsoft.Web.Mvc

You can see that System.Web.Mvc is referenced by 7 assemblies in my bin folder. Some reference
version and some version I can now resolve any conflicts.


Neil Barnwell said...

Holy smokes are you spying on me? This is exactly the problem I've been having the last couple of days. I've been using PowerShell in a similar way, but not looking at the references inside files (I was using Reflector for that), more to find out what versions of what assemblies are where in my working copy.

Something like this:

PS C:\data files\projects> gci -Filter Castle.Core.dll -r | %{ $_.VersionInfo } | group-object ProductVersion

stuart cullinan said...

Awesome, this helped me today...cheers.

Ɓukasz Podolak said...

Thanks Mark, this has already helped me.

Marco said...

very nice and usefull little tool. maybe a SortedDictionary would be nice for the output. thanks!

Mike Hadlow said...

Marco, do you mean sort the dependencies by name?

Marco said...

Was talking about sorting the references on namespace for easy searching, but maybe the other way around might be useful too.

Anonymous said...

great work

Anonymous said...

... or you may add the following to the section of your *.config file:

Anonymous said...

*---assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"---*
*---assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /---*
*---bindingRedirect oldVersion="" newVersion="" /---*

Replace *--- with a less-than and ---* with a greater-than symbol.

Anonymous said...

I'm having a terrible time getting this to work on projects that reside on a network share. Any ideas of how to get it to work? I'm getting a "Failed to load assembly: " error.


Hoang Tran said...

Thank you, this helped me.
I run it in another way: cd to your bin, then:

C:\alreay\at\bin\asmspy .

Unknown said...

Brilliant! Helped me so much :)

Anonymous said...

Thanks. Any change you can add *.EXE, in addition to *.DLL?

Mike Hadlow said...

Hi Anonymous, done, just get the latest from GitHub.

Stuff said...

Maybe you can add a switch for just displaying conflicts? Scanning through my output of 1500 lines takes a lot of time. =)

Mike Hadlow said...

Stuff, pull request?

Anonymous said...

Great tool!

Craig said...

This sorted my TFS build issue out. Thanks.

Jeramy Rutley said...

Thanks for sharing this... it's awesome!

Nathan said...

This worked extra special nice. Thanks!

Anonymous said...

Awesome tool, helped me out a ton!

AimlessInLA said... I can see where the problem is, but how do I fix it when the conflict seems to be at least two levels deep?

I first noticed the problem in my project when the embedded server in VS started aborting with DotNetOpenAuth.Core conflicts. I then noticed the mapping conflict warnings, then found this page and downloaded AsmSpy. I'll just give one example from my AsmSpy output. Most references listed to mscorlib are, but one is's from DotNetOpenAuth.Core which also calls!

I strongly suspect most of my problems are coming from dotnetopenauth, but I don't know what dotnetopenauth is, or how it got there, because it's not a reference that explicitly added. I'm just treading water here, and all but desperate for a resolution.

Neil Moss said...

Thank you very much. Took me straight to the root of my issue of the day.

BeaK said...

Thanks for that very useful tool. It showed me exactly where my problem was.

Bas Hamer said...

this is totally awesome, get to go home now :)

Mikael Koskinen said...

Excellent! I'm not sure how I've missed this tool before, as it's priceless. I've been having some reference problems in a WP7 app and the Visual Studio's info outputs haven't been useful. With this tool it took only few minutes to figure out the problem!


jlb23sa said...

Yes, a terrific tool. Thanks for contribution