Wednesday, June 17, 2015

.Net assembly loading problem

So I had a problem at work today. I built my .net winforms application in visual studio, copy the bin/ and 
make sure I can start the application locally without issue. Then I hand it over to someone else, and 
boom, the application won't even load, with this dialog box popping up.


I didn't have the option to debug the program, and I couldn't reproduce the problem where I was. 
So I had to find another computer, change the application build mode to Console, so my 
Console.WriteLine would actually show up. I've traced the problem to a missing DLL.

The issue was that a certain library wasn't deployed in the bin/ directory Visual studio built, but it 
So the solution was easy, once the problem was identified.
But this got me thinking, how can I detect this sort of problem ?
I've started playing with DebugDiag, and build my own little application which throws an Exception 
Since now I know beforehand what the problem was, I could focus on which tools allow me to debug it. 

was in the GAC for me.

when clicked. I've managed to generate dumps, and load the actual exception. But I couldn't get it to 
work with my real program. Debug simply didn't recognize my application crashing.

So I found three tools/solutions :

Method 1 : FUSLOGVW.exe (Assembly Binding Log Viewer)
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\x64

The tool itself is horrible. It won't log anything unless you set up the custom log path. Once that is done,
 here we go :

Method 2 : Ilspy.exe : (
  1. Simply load the main .exe file, and explore each referenced DLL. Here, The Krypton 
  2.  library just won't show up.

Method 3 : Process Explorer
This one is tricky. Add custom load rules in process explorer as follows

And look for failed dll lookups in the application directory :

Bonus points :
The event viewer was my key to success in this case :

But it didn't mention which file and why.

On some other computer, I didn't even get the famous error dialog box, so
I had to enable it :