Aug 282014
 
What’s DEVPATH

Being a .net developer you might have wondered if at all there is a way to tell .net assembly binding and loading mechanism (fusion) to look for your assemblies in your shared assembly folder as well. This will be really helpful if your assembly is used with multiple applications so that if they fail to locate an assembly in the appbase or privatepath’s then they start looking for it in your ‘bin’ folder. This prevents you from frequently installing and uninstalling the assembly to GAC for testing purpose.

This is exactly what DEVPATH environment variable does.

How to set DEVPATH

Following example shows you how to setup just need to set assembly look up path to this variable. For e.g.

set DEVPATH=”c:\sharedassemblies\”

To enable DEVPATH look up you’ll also need to modify machine.config file, in my case its located here: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config

<configuration>

<runtime>
<developmentMode developerInstallation=”true”/>
</runtime>

</configuration>

Verify DEVPATH is used

So next time when application runs and starts looking for your assembly it will for sure look in the above path. If fusion logger is enabled and if you open the log file for your assembly you should see something like this…

===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\myapp.exe.Config
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: Found assembly in DEVOVERRIDE path C:\sharedassemblies\Test.DLL

Recently had a customer who asked this question and this looks like to have helped them so thought of sharing this out with you folks as well.

Watch outs
  1. Please be very aware that you’ve set this feature on. You could end up having erratic behavior if somehow DEVPATH has a path containing unsupported path chars like parentheses or if DEVPATH is set to empty.
  2. Please only use this feature in development environments as this feature by passes all normal assembly lookup features as fusion looks up DEVPATH first if enabled.
  3. Please note fusion will look up DEVPATH as if its an AppBase folder so be aware that it will look up subdirectories as well in this DEVPATH. Also all valid assembly name look ups will be done, for e.g. .dll, .exe etc.
Sep 232013
 
What is fusion

Fusion is the module in .net which manages binding of .net assemblies. So the question here is why do we need to setup fusion logs. Since we know that fusion is module which is responsible for assembly bindings, its good to know that it also emits verbose logs known as fusion logs. These log entries lists out the activities that fusion does for loading an Assembly. The logs will also show us why a particular Assembly failed to load: this is why most folks enable fusion logger.

Fusion logging is not turned on by default. We’ll have to turn it on via registry entry or use fuslogvw.exe to set verbosity of fusion logging: for e.g. what needs to be logged, bind failures?

The fusion module comes into play during Assembly binding phase. We can request binding via automatic references in project or via explicit code requests etc.

What is an Assembly

An Assembly in .net is made of the following components…

image

In short Assembly is made up of a manifest file (the main module) and can also have other module files as well. The manifest metadata will have references to the other modules that an Assembly has.

How to enable fusion logging
Using FusLogVw tool

Please follow these steps to enable fusion logging.

1. Run Visual studio 2010 command prompt as admin.
2. Run fusion log tool: fuslogvw.exe. Fuslogvw should be there in your SDK folder, in my case…
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\FUSLogvw.exe. You can as well run it directly from your Visual Studio command prompt.
fusionlogvw
If fusion log viewer is not installed on your machine, then add the registry entries given below manually and check out the log folder for output.
3. Open the settings dialog as shown in above image by clicking on the “Settings” button.
4. Enable “Log all binds to disk”.
5. Check “Enable custom log path”.
a. Enter a custom fusion log path, in my case I used “C:\FusionLog”.
6. Say “Ok”.
7. Go ahead with execution of your application. If you restart/refresh the log viewer you should see log entries as shown in the above screenshot.

If FusLogVw is missing…

Following registry entries get added to the registry when you enable options via above settings dialog of fuslogvw.exe. Just in case if you don’t have fuslogvw.exe installed on your box add the relevant one manually into the registry or you can create a .reg file which does this consistently.

  • Log all binds to disk
    • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion\ForceLog = 1
  • Log bind failures to disk
    • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion\LogFailures = 1
  • Log in exception text
    • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion\EnableLog = 1
  • Log Disabled
    • No entry.
  • Enable custom log path
    • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion\LogPath = c:\fusionlog
Viewing logs in the fusion folder

Click on any of the log entries in the above log viewer, entries are saved to disk in html format, the corresponding html file will open in your default browser. You can also view the entries directly by opening the log folder contents directly, in my case c:\fusionlog.

image

The last line mostly says whether the assembly loaded successfully or not. The lines before that will tell why the loading failed. Instead of “Log:” you’ll see something like “WRN:”/”ERR:” etc.

Fusion log viewing is the best way to figure out Assembly load issue.