We were defining custom tasks for MSBuild to call the
XsltCompiler executable to generate an assembly - Chocolate.Cake.dll. But I kept getting a runtime error saying that "Could not load file or assembly '
Chocolate.Cake' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from
I tried to clean build everything to ensure that an older version is not being picked up. No luck for me. I was wondering whether an older assembly was getting bound. I realized the best option to see why this binding was failing by using the Assembly Binding Log Viewer.
Assembly Binding Log Viewer
The Assembly Binding Log Viewer provides the information on why an assembly can't be located by the .NET Framework. It's installed with Visual Studio and with the Windows SDK.
To see the details, I had to run the utility with admin rights (Fig 2).
I clicked Settings, and selected the Log bind failures to disk radio option. After refreshing, as seen in snapshot 3, I could see an entry for my
Chocolate.Cake assembly, confirming the failure.
Fig 3: Assembly Viewer
Fig 5: Log Contents
In my case, I viewed the log, and for the scenario described in the background, I noticed that an attempt was made to find the Chocolate.Cake.dll.DLL! Turns out that when using MSBuild for the custom task, in my build proj file, my input parameter of assembly name also incorrectly included an extension of DLL. I had to change this assembly name to
Chocolate.Cake from Chocolate.Cake.dll and everything worked fine after this.
You can obviously customize where the logs can be saved, etc. Additional details can be found here.
This has been a very brief introduction to a very useful utility which can help in diagnosing why an assembly bind failure is occurring.