Click here to Skip to main content
Click here to Skip to main content

Investigating Managed Assembly Load Failures

, 16 Jul 2014
Rate this:
Please Sign up or sign in to vote.
How to troubleshoot managed assembly load failures?

Introduction

We are often faced with a problem where an assembly fails to load. There could be various reasons for the load failure:

  1. An assembly being probed could not be located.
  2. Version mismatch or an assembly of diffrent version was already loaded by the process.
  3. A dependency could not be found or resolved.

It sometimes is cumbersome to troubleshoot such scenarios and, having had the similar experience a couple of times made me search for a way to achieve it especially on environments where there are no Visual Studio or .NET tools.

I came across Fusion Log Viewer (fuslogvw.exe) which is a part of .NET tools and helps in capturing all assembly binding information on the machine. However, good thing is that it's just a log viewer that comprehends the log files and dumps the information on a neat grid. But, it not required to enable or capture the logs which makes it a perfect fit for production environments.

Using the code

All we need to do is set a couple of registry entries to enable logging. Here are the keys that you can easily configure.

Add the following values to:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion

Add the following keys:

  • ForceLog [DWORD]: Set it to 1 to enable logging information of all assembly bindings on the machine.
  • LogFailures [DWORD]: Set it to 1 to enable logging failures during assembly loads.
  • LogResourceBinds [DWORD]: Set it to 1 to enable logging information about all resource bindings.
  • LogPath [String]: Set it to the folder where you want the log files to be created (e.g. C:\Logs\FusionLog\)

Note:

  • Make sure you include the backslash after the folder name and that the Folder exists.
  • You need to restart the program that you're running to force it to read those registry settings.

You may put these settings in a reg file to set/update the same quickly e.g.

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion]
"LogFailures"=dword:00000000
"LogPath"="C:\\FusionLog\\"
"LogResourceBinds"=dword:00000001
"ForceLog"=dword:00000000

 

Once again try and repro the scenario where the assembly load failed, open the log folder and there you go... the logs are very easy to read and understand Smile | :)

Interpreting the log files

Once you've enabled the logging and restarted your application which fails to load an assembly, you see some log files in fusion log path you have configured. Now:

  1. The logs are contained in a folder named by the host process which tried to load the assembly.
  2. The log files inside this folder are named by the assembly which failed to load.
  3. And, finally the data inside the log file will tell why/how the probing failed.

Here's a sample log content:

<meta http-equiv="Content-Type" content="charset=unicode-1-1-utf-8"><!-- saved from url=(0015)assemblybinder: --><html><pre>
*** Assembly Binder Log Entry  (7/3/2014 @ 4:11:21 PM) ***

The operation failed.
Bind result: hr = 0x80131040. No description available.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\Program Files\XXXX\YYYY.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = ABCD, Version=5.1.0.25, Culture=neutral, PublicKeyToken=a38ab61cdab78c6a
 (Fully-specified)
LOG: Appbase = file:///C:/Program Files/XXXX
LOG: Initial PrivatePath = C:\Program Files\XXXX
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = YYYY.exe
Calling assembly : PQRS, Version=5.1.0.25, Culture=neutral, PublicKeyToken=a38ab61cdab78c6a.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Program Files\XXXX\YYYY.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: ABCD, Version=5.1.0.25, Culture=neutral, PublicKeyToken=a38ab61cdab78c6a
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Program Files/XXXX/ABCD.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Program Files\XXXX\ABCD.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: ABCD, Version=5.2.0.5012, Culture=neutral, PublicKeyToken=a38ab61cdab78c6a
WRN: Comparing the assembly name resulted in the mismatch: Minor Version
ERR: The assembly reference did not match the assembly definition found.
ERR: Run-from-source setup phase failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

Here, YYYY.exe loaded an assembly PQRS.dll which has a dependency on ABCD.dll (version 5.1.0.25) but on the machine it could only find ABCD.dll (version 5.2.0.5012).

The log indicates the failure in load because of mismatch in Minor Version of the assembly. Hence, the load of PQRS.dll fails as it's dependent assembly could not be loaded.

History

[16-Jul-2014 Update]: Added the section <Interpreting the log files> as requested.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

himanshu agarwal
Software Developer (Senior)
India India
No Biography provided

Comments and Discussions

 
Generalnice ... PinmemberSharath C V15-Jul-14 20:30 
Generaluseful PinmvpAkhil Mittal15-Jul-14 19:26 
GeneralThoughts PinpremiumPIEBALDconsult15-Jul-14 6:26 
GeneralRe: Thoughts Pinmemberhimanshu agarwal16-Jul-14 18:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 16 Jul 2014
Article Copyright 2014 by himanshu agarwal
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid