One requirement of the XAML Power Toys Visual Studio Add-In is that the code must load and reflect assembly types that are currently being edited in Visual Studio. In order to prevent file locking problems of the reflected assemblies, developers must load the required assembly in a secondary AppDomain; do the required processing and unload the secondary AppDomain.
When I was developing XAML Power Toys, I was running into FileNotFoundExceptions when attempting to load the current or different assemblies into another AppDomain. I couldn’t figure out why I was getting the exception. So I searched around the Internet, found other developers asking the same question. I then ran into a post describing the following registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion\EnableLog
By adding a REG_DWORD registry key named EnableLog and setting the value to 1, the FusionLog property on the FileNotFoundException will be populated with the reason the assembly couldn’t be loaded. This information is available at even on release builds of your program that is having this problem.
The following exceptions have a FusionLog property that will be populated when an assembly fails to load, the run-time throws the exception and the EnableLog key has a value of 1.
FusionLog Property Information
If you do not have the above FusionLog registry setting set to 1, you will get the following text added to the bottom of the exception ToString output.
To enable the populating of the FusionLog property set the below EnableLog registry key to 1. If the EnableLog key has not yet been added, you’ll need to do this.
After you have enabled the FusionLog property and you get a FileNotFoundException during assembly loading, the following text (similar text) can be read from the FusionLog property of the exception:
=== Pre-bind state information ===
LOG: User = MyComputerName\karl
LOG: DisplayName = TroublesootFileNotFoundException, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///c:/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\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:/TroublesootFileNotFoundException.DLL.
LOG: Attempting download of new URL file:///c:/TroublesootFileNotFoundException/TroublesootFileNotFoundException.DLL.
LOG: Attempting download of new URL file:///c:/TroublesootFileNotFoundException.EXE.
LOG: Attempting download of new URL file:///c:/TroublesootFileNotFoundException/TroublesootFileNotFoundException.EXE.
The above log information details the steps that the .NET run-time executes when attempting to load the requested assembly. The above path, filename and search paths give you the necessary information to easily troubleshoot why an exception is being thrown.
What is very nice about this feature, is that you can get this same excellent debugging information from deployed release build applications. Just ensure you capture the exception and log the information for analysis of the problem.
Demo Application
I have included a demo application that when launched, creates a secondary AppDomain, executes a method that returns a String that is displayed in the console.
Un-commenting the following line of code in the demo application will cause a FileNotFoundException to be thrown when the run-time attempts to load the assembly in the secondary AppDomain.
‘objAppSetup.ApplicationBase = “c:\temp”
You can then add the above registry key and see how this setting will benefit your troubleshooting of applications running in release build, not inside Visual Studio.
Download
After downloading the below package you must rename the extension from .DOC to .zip. This is a requirement of WordPress.com.
Download TroubleShootingFileNotFoundException (15 KB)
Video
The below video walks you through the demo application and setting up of the above required registry key.

The video links require Microsoft Silverlight 1.0. If you do not have it, you will be prompted to install it when you click one of the links. After the short installation is completed, close the browser window that you did the install in and re-click the video you want to watch. You can also download it here. Windows XP or Vista required.
Troubleshooting FileNotFoundException when loading secondary AppDomains
Have a great day.
Just a grain of sand on the worlds beaches.