Ok, so you've written your share .NET assemblies (by this I mean both .dlls and .exes) in C# or VB.NET ... or even better, COBOL! But have you ever wondered how it all happens? It is just smoke and mirrors? If any of you have read (or are currently reading) Jeffrey Ritcher's book, Applied .NET Framework Programming, you can recall that in pages 9-18 he gives you a pretty good run down of how the CLR is loaded when you execute a simple program, for example the infamous Hello World.

But this post is not about Richter's book example (although, that is a good idea for another post!), it is about a tool under the .NET SDK called FUSLOGVW.EXE (Fusion Log Viewer). The Fusion, or Global Assembly Cache (GAC), APIs the internal name for the components that make up the CLR's assembly loader and binder. These classes reside in the un-managed DLL called fusion.dll (located under the .NET Framework installation folder). The Fusion API provides information about the actual location of an assembly by providing several assembly caches, they are:

  • Global Assembly Cache (GAC) - Home for all shared assemblies    
  • Download Cache - Home for the assemblies you dowload/use from an external URL    
  • 'ZAP' Cache - Home for the pre-compiled native assembly images (generated by ngen)

If you would like to read more about the Fusion API, check out this KB article. Also, this article in CP has a great example of how to use the Fusion API from within .NET by using the corresponding classes under the mscorcfg assembly.

Ok, now back to the log viewer. First of all, the location of the log viewer is that of FX_SDK_HOME\Bin\FUSLOGVW.EXE, here the FX_SDK_HOME is the folder were you have installed the .NET SDK (if you have VS.NET installed, this is under the %PROGRAM_FILES%\Microsoft Visual Studio.NET 2003\SDK folder).

Now, out of the box, the viewer does nothing. This is due to some missing information in the registry. Do the following to fix this problem:

  1. Using regedit, add the a new string value called LogPath to the following entry: HKLM\Software\Microsoft\Fusion
  2. Set the value of this string to a folder in your C drive called fusionlogs (ie. C:\fusionlogs)
  3. Create a folder under the C drive called fusionlogs
  4. Add a new DWORD value called ForceLog under the same entry as in step 1. Set the value to 1

After making these changes to registry, re-open fuslogvw.exe, check Log Failures and select the Custom option. Now, you can do one of two things...You can start up your favorite .NET application or you can use one of the examples that I created for this post. I recommend that you use my examples because they are very simple .NET applications. One, SimpleFusion.exe is a very simple console application that prints out a message to the console. AdvancedFusion.exe also prints out a message, but it does it by using a class called FusionHelper that's under the FusionHelper.dll assembly. Here are the screen shots from fuslogvw from both of these examples:

Simple Fusion Example

Simple Fusion Example

Advanced Fusion Example

Advanced Fusion Example

For kicks, I say start up VS.NET and see all the .NET assemblies that it loads. To view the content of the logs, you can either double click the entry or select it and then click the View Log button.

Now you might be asking yourself, when would I use fuslogvw? Well, since this tool is a viewer for the logs generated by the assembly loader subsystem, it can help you trouble shoot why an assembly is not loading! In other words, if you have ever gotten a FileNotFoundException, FileLoadException, BadImageFormatException then fuslogvw can help you troubleshoot the cause. All you have to do is attempt to load the assembly and after you get the error, open up fuslogvw and see where the binding fails.

If any of you have any questions or would like more information, please feel free to contact me via a comment. Happy d-buggin'