Fusion Log Viewer: The binocular to assembly binding
Tags: softwaredevelopment, debugging, dotnet, csharp
Published: 2020-02-05 08:25:34

---
title: Fusion Log Viewer: The binocular to assembly binding
published: true
date: 2020-02-05 08:00:29 UTC
tags: software-development,debugging,dotnet,csharp
canonical_url: https://medium.com/@dvirsegal/fusion-log-viewer-the-binocular-to-assembly-binding-cbac18f824df
---

## Investigating .NET assembly loading (binding) issues

![](https://cdn-images-1.medium.com/max/1024/0*hwGHUCqcLqYBc43F)<figcaption>Photo by <a href="https://unsplash.com/@slvrstvk?utm_source=medium&amp;utm_medium=referral">NICK SELIVERSTOV</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption>

Once in a while, you encounter that peculiar problem when you run your application and receive an exception saying _TypeLoadException_ or _FileNotFoundException_ even though the DLLs that your application relies on, are right there!

![](https://cdn-images-1.medium.com/max/720/0*PSN_oPC5_KNgBdgS.jpg)

The first suspect that may jump to your head is an assembly binding issue since it happens at the moment you run your application. It might be a mix of old DLLs with new ones, mismatch in version numbers or cultures, missing assemblies at the application’s folder, or even a probing failure, either of each — fusion log viewer can assist in identifying the case.

![](https://cdn-images-1.medium.com/max/883/0*gPfC_cdIaphi7eQz.png)<figcaption>fuslogvw — <a href="https://github.com/awaescher/Fusion?WT.mc_id=-blog-scottha">source</a></figcaption>

This lifesaving tool is [installed](https://docs.microsoft.com/en-us/dotnet/framework/tools/fuslogvw-exe-assembly-binding-log-viewer) as part of Visual Studio installation on your development system and has to run with **administrator** privileges.

According to [MSDN](https://docs.microsoft.com/en-us/dotnet/framework/tools/fuslogvw-exe-assembly-binding-log-viewer), this viewer:

> The Assembly Binding Log Viewer displays details for assembly binds. This information helps you diagnose why the .NET Framework cannot locate an assembly at run time. These failures are usually the result of an assembly deployed to the wrong location, a native image that is no longer valid, or a mismatch in version numbers or cultures.

#### The basics

I _highly_ recommend to change the default log location (at Internet Explorer cache) into a custom clean folder; this can be done on the ‘Log Settings’ dialog. Thus you bypass issues with the default location that causing the log to stop showing new entries because IE cache can get corrupted and prevent read and write operations by the .NET binding infrastructure.

Personally, I prefer to log only binding failures. In such a way, I’m able to see only the required information for understanding my problem, prevent disk flooding, and causing each .NET application slowdown (since logs are being gathered). Once turned on, you can immediately identify your failure. Just double click on the selected entry and the following information will be [displayed](https://docs.microsoft.com/en-us/dotnet/framework/tools/ngen-exe-native-image-generator):

> 1. The specific reason the bind failed, such as “file not found” or “version mismatch”.

> 2. Information about the application that initiated the bind, including its name, the application’s root directory (AppBase), and a description of the private search path, if there is one.

> 3. The identity of the assembly the tool is looking for.

> 4. A description of any Application, Publisher, or Administrator version policies that have been applied.

> 5. Whether the assembly was found in the [global assembly cache](https://docs.microsoft.com/en-us/dotnet/framework/app-domains/gac).

> 6. A list of all probing URLs.

Below a synthetic example I created:

```
\*\*\* Assembly Binder Log Entry (2020–01–26 @ 16:28:09) \*\*\*

The operation failed.

Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll

Running under executable C:\Example.exe

— — A detailed error log follows.

=== Pre-bind state information ===

LOG: DisplayName = Foo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

(Fully-specified)

LOG: Appbase = file:///C:/

LOG: Initial PrivatePath = NULL

LOG: Dynamic Base = NULL

LOG: Cache Base = NULL

LOG: AppName = Example.exe

Calling assembly : Example, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.

===

LOG: This bind starts in default load context.

LOG: No application configuration file found.

LOG: Using host configuration file:

LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.

LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).

LOG: Attempting download of new URL file:///C:/Foo.DLL.

LOG: Attempting download of new URL file:///C:/Foo/Foo.DLL.

LOG: Attempting download of new URL file:///C:/Foo.EXE.

LOG: Attempting download of new URL file:///C:/Foo/Foo.EXE.

LOG: All probing URLs attempted and failed.

\*\*\* Assembly Binder Log Entry (2020–01–26 @ 16:28:09) \*\*\*

The operation failed.

Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll

Running under executable C:\Example.exe

— — A detailed error log follows.

=== Pre-bind state information ===

LOG: DisplayName = Foo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

(Fully-specified)

LOG: Appbase = file:///C:/

LOG: Initial PrivatePath = NULL

LOG: Dynamic Base = NULL

LOG: Cache Base = NULL

LOG: AppName = Example.exe

Calling assembly : Example, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.

===

LOG: This bind starts in default load context.

LOG: No application configuration file found.

LOG: Using host configuration file:

LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.

LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).

LOG: Attempting download of new URL file:///C:/Foo.DLL.

LOG: Attempting download of new URL file:///C:/Foo/Foo.DLL.

LOG: Attempting download of new URL file:///C:/Foo.EXE.

LOG: Attempting download of new URL file:///C:/Foo/Foo.EXE.

LOG: All probing URLs attempted and failed.
```

According to the log, the assembly binder searches for _Foo_, whether it is a DLL or an executable. First, it looks for an application configuration file to understand where to load its dependencies (probing), when it can’t find it, the default host configuration is loaded and then looks for _Foo_ locally. When not found, an exception is being thrown.

You can do additional basic operations such as delete one entry or all of them and refresh the interface to get new entries.

Furthermore, you can bind for native images created by [Ngen (Native Image Generator](https://docs.microsoft.com/en-us/dotnet/framework/tools/ngen-exe-native-image-generator)), under the ‘Log Categories’ group. If you desire to get details of apps running in the Windows app container, then enable the immersive logging option.

#### Fusion++

![](https://cdn-images-1.medium.com/max/800/0*s-GEDLU3oGkI_se1)

Thanks to [Andreas Wäscher](https://github.com/awaescher), we don’t have to deal with all of these settings. He developed, in his own words, a modern alternative for fusion log viewer, named Fusion++ that can be downloaded from here:

{% github awaescher/Fusion%}

After running it, just hit the ‘Record’ button to capture assembly logs, and when done, click on ‘Stop.’ His app parses all the log files, highlights the parsed warning and failure to quickly identify issues, as seen below in the same tailored failure example:

![](https://cdn-images-1.medium.com/max/1022/1*J6oHiSfaRRddEJ7_SL_8GA.png)

![](https://cdn-images-1.medium.com/max/818/1*LXOu3bUDorS979bU0aNEZg.png)<figcaption>Highlighted error in Fusion++</figcaption>

Look how easy to find what went wrong. An error line is marked in red, and when you double click on it, you can see the loading failure.

Furthermore, logs are being saved into the Windows Temp folder to easily clean them using ’Cleanup Windows Tools,’ besides it allows seeing previously recorded sessions. More advanced features are the grid annotations that indicate events over the app scrollbar and the parser range selector.

[![](https://cdn-images-1.medium.com/max/973/1*DjRCGuN1o7zekeVBAbtNTQ.gif)](https://github.com/awaescher/Fusion/releases)<figcaption>Parser range selector</figcaption>

To conclude, Assembly load failures and binding redirects can make any .NET developer frustrated, thus this open-source desktop app touches a soft spot and acts as a real game-changer. It allows you to spend your time wisely, instead of diagnosing binding errors. So, go ahead and use it.