919

How do I enable assembly bind failure logging (Fusion) in .NET?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user32736
  • 10,221
  • 3
  • 18
  • 6
  • 50
    If anybody cares, to use fusion logger (fuslogvw.exe) read this article: http://msdn.microsoft.com/en-us/library/e74a18c4(v=VS.100).aspx it tells you where to download it and other info. –  Jun 13 '11 at 14:51
  • 13
    @Will - thanks for sharing! As a bonus - make sure you run `fuslogvw.exe` as an administrator to avoid any rights issues. – SliverNinja - MSFT Feb 27 '12 at 16:41
  • 3
    As a related note, be sure to turn fusion logger (fuslogvw.exe) off when you are done. My "C:\Windows\...\Temporary Internet Files\" folder had 4 million logs in it. The total size of all the files was 6 GiB, but since they were much smaller than the cluster size, the actual disk space used was 16 GiB. – tehDorf Apr 05 '16 at 19:45
  • 16
    @Will I disagree that installing fuslogvw is the "best" answer. If you could get just the tool without having to install the whole Windows SDK on what is likely not a development environment then you'd have a point. – Coxy Apr 18 '16 at 05:25
  • 2
    @Will Certainly, but the answer you link to does not cover any of that. – Coxy Apr 19 '16 at 00:09
  • @Coxy Does it have to? Does it really have to cover the obvious? Perhaps you should edit it and include this important information. As for this conversation, I must bid it adieu. Good day to you, sir. –  Apr 19 '16 at 13:06
  • 1
    @Coxy the best answer is to use ETW to trace it on demand and not all the time: http://stackoverflow.com/a/29374658/1466046 Here you can transfter the file to a differnet PC and analyze it in depth (Also image load event + callstacks). This is MUCH deeper compared to the old fusion log. – magicandre1981 Jun 10 '16 at 04:34
  • 1
    @Coxy having a polished Fusion logger without the Windows SDK is possible: https://stackoverflow.com/a/56067961/704281 – Waescher Jul 26 '19 at 13:38
  • Note that `.Net Core` does not log anything at all in the `FusionLog`. – Louis Somers Jun 11 '21 at 09:50

14 Answers14

979

Add the following values to

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion
Add:
DWORD ForceLog set value to 1
DWORD LogFailures set value to 1
DWORD LogResourceBinds set value to 1
DWORD EnableLog set value to 1
String LogPath set value to folder for logs (e.g. C:\FusionLog\)

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.

By the way, don't forget to turn off fusion logging when not needed.

enter image description here

Hakan Yildizhan
  • 172
  • 1
  • 9
Gary Kindel
  • 17,071
  • 7
  • 49
  • 66
  • I added those entries, but my c# express (2010) still tells me "Assembly binding logging is turned OFF". How to make it work? – newman Nov 11 '10 at 02:27
  • 5
    Been reported by some that registry change does not take right away. Have you tried turning Fusion logging on then rebooting? – Gary Kindel Dec 06 '10 at 20:18
  • 60
    You need to restart whatever program it is you're running for it to read those registry settings – Orion Edwards Mar 28 '11 at 22:29
  • 27
    Gary's solutions worked for me although I also had to follow by resetting IIS. Note I configured this in a clean environment where I didn't want to install SDKs and the like. – Michhes Jul 30 '10 at 02:21
  • Where exactly is the HKEY_LOCAL_MACHINE folder located? – Art F Nov 16 '12 at 16:19
  • @ArtF: That's a location in the registry. – David Schmitt Dec 11 '12 at 12:12
  • 60
    The Fusion Log Viewer does all that for you. Go to Start -> Programs -> Visual Studio xxxx > Visual Studio Tools > Visual Studio Command Prompt (run as admin) and type "fuslogvw". In Settings you adjust the logging. – r3mark Jun 04 '13 at 03:09
  • 13
    To turn on/off logging handy, I've created .reg files, which are based on Gary Kindel's answer: [enabling](http://pastebin.com/PmKQ0hgn) and [disabling](http://pastebin.com/NBivNkcu). – Igor Kustov Nov 19 '13 at 07:16
  • 2
    Enabling fusion log can have severe performance impact over time. My Visual Studio experience deteriorated over time, only to find that fusion logging was enable. Remember to disable it after use. – Chandermani Jul 11 '14 at 06:10
  • 2
    When using Fusion Log on Azure machine make sure to put log files on the same disk as application. Ex. web app is deployed to `F:\sitesroot\0`. Log to `F:\fusionlog\`. Create that dir before. – Fosna Oct 16 '14 at 13:11
  • 1
    @r3mark It doesn't put the trailing slash for the folder though. – James Poulose Aug 31 '15 at 02:25
  • 4
    But.. REMEMBER TO TURN IT OFF. I just lost a day troubleshooting slow IIS, and it's due to me turning on Fusion Logging but not turning it off. 10 Gb of files later.... Procmon.exe saved the day. – Gumzle Oct 13 '15 at 07:35
  • From my experience, you should NOT put this under the Wow6432Node key, even if your application runs 32-bit. – AJ Richardson Apr 12 '17 at 20:31
  • 1
    If you don't disable logging, it starts taking gigs in a short amount of time. – Tarik Jun 15 '17 at 19:33
  • Very useful. If you want a handy powershell script to set/remove these values: https://gist.github.com/guylangston/3e181128672e1d1a15d852a56a5f7164 – Guy Langston May 04 '20 at 17:15
301

I usually use the Fusion Log Viewer (Fuslogvw.exe from a Visual Studio command prompt or Fusion Log Viewer from the start menu) - my standard setup is:

  • Open Fusion Log Viewer as administrator
  • Click settings
  • Check the Enable custom log path checkbox
  • Enter the location you want logs to get written to, for example, c:\FusionLogs (Important: make sure that you have actually created this folder in the file system.)
  • Make sure that the right level of logging is on (I sometimes just select Log all binds to disk just to make sure things are working right)
  • Click OK
  • Set the log location option to Custom

Remember to turn of logging off once you're done!

(I just posted this on a similar question - I think it's relevant here too.)

Phil
  • 6,561
  • 4
  • 44
  • 69
Mike Goatly
  • 7,380
  • 2
  • 32
  • 33
  • 4
    Note that in cases where you are hosting the runtime yourself from a native application you will be required to use a custom log path for some reason otherwise you won't get anything logged. – jpierson Oct 04 '12 at 03:34
  • At least in my situation, I didn't actually have to set the custom log paths. All I had to do was turn logging on, e.g., "Log all binds to disk" on the settings dialog. – Josh Jul 31 '14 at 20:11
  • 51
    Run as Administrator was required in my case, otherwise all options were disabled. – vezenkov Aug 12 '16 at 12:32
  • If you are trying to use the Fusion Log Viewer in conjunction with Visual Studio I've found that I had to launch the log viewer and then restart Visual Studio as otherwise the viewer doesn't seem to log VS bind fails. – The Senator Mar 23 '17 at 16:17
  • 2
    Note: create the folder as Admin! – Tabrock May 10 '17 at 21:07
  • 6
    Make sure you are running `fuslogvw` not only as admin but also from the **correct** Windows SDK path the Visual Studio project throwing the exception is using. Check its csproj and search for SDK within (my sdk node is named `TargetFrameworkSDKToolsDirectory`). Using a non matching fuslogvw version seems to not catch the exceptions (which makes sense...) – Veverke Jun 12 '17 at 14:28
  • Thanks for the reminder to turn off logging once you're done. I assumed (very silly to just assume) that it only logged when running fusion log – Tristan van Dam Nov 09 '17 at 10:05
  • Adding to @Veverke's comment: "Search everything" app says latest ones on my pc are under "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.1 Tools"; AFAIK using the highest listed SDK version is a good strategy (I don't think you need to use an OLDER fuslogvw, even if you are using an older VS.) – ToolmakerSteve Apr 10 '18 at 11:56
196

If you have the Windows SDK installed on your machine, you'll find the "Fusion Log Viewer" under Microsoft SDK\Tools (just type "Fusion" in the start menu on Vista or Windows 7/8). Launch it, click the Settings button, and select "Log bind failure" or "Log all binds".

If these buttons are disabled, go back to the start menu, right-click the Log Viewer, and select "Run as Administrator".

Samuel Jack
  • 32,712
  • 16
  • 118
  • 155
  • 6
    Those buttons are disabled for me - why? – Tim Lovell-Smith Aug 24 '10 at 22:11
  • 14
    @Tim, not seen that before - could it be to do with Admin privileges? It is HKEY_LOCAL_MACHINE that is being modified after all. – Samuel Jack Sep 24 '10 at 15:35
  • 2
    "Settings, Log bind failures" was enough to find my problem. – pauloya Aug 16 '11 at 12:00
  • 1
    Make sure the folder allows write access. UAC and c:\logs do not play nice with the fusion log – Edward Wilde Feb 20 '13 at 09:27
  • 4
    Just as a note, if the buttons are disabled, re-run fusion log viewer with admin privileges. – Bruno Lopes Mar 07 '13 at 19:33
  • 1
    If you aren't seeing any output Reboot your PC. I experienced this with .NET 4.6 + VS2015 on clean PC just with .NET 4.6 tools folder copied over. Note if you are told errors about the custom path when you set it (and you think it's telling you lies) press OK on the settings dialog a few times anyway and it'll ignore the error. – GilesDMiddleton Sep 08 '15 at 14:58
  • As I wrote in a comment to @MikeGoatly's answer, I think you need to make sure you are picking the correct fuslogvw.exe, from the correct Windows SDK folder. Check which SDK folder is in use by looking into the .csproj of the project you are running. – Veverke Jun 13 '17 at 08:52
111

You can run this Powershell script as administrator to enable FL:

Set-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name ForceLog         -Value 1               -Type DWord
Set-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name LogFailures      -Value 1               -Type DWord
Set-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name LogResourceBinds -Value 1               -Type DWord
Set-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name LogPath          -Value 'C:\FusionLog\' -Type String
mkdir C:\FusionLog -Force

and this one to disable:

Remove-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name ForceLog
Remove-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name LogFailures
Remove-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name LogResourceBinds
Remove-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name LogPath
Tereza Tomcova
  • 4,928
  • 4
  • 30
  • 29
  • 6
    Thanks! I've allowed myself to put your commands into [this gist](https://gist.github.com/teamaton/3093a8ee66433a278fd5). And I added creation of the `c:\FusionLog` dir so that people don't forget that ;-) – Oliver Oct 30 '15 at 21:44
  • This answer is way more useful, I put it into my scripts last time. Now few months later, I came back here and saw the thread again. Remind me of how I use it last time. – cwhsu Jul 12 '20 at 09:14
94

Set the following registry value:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion!EnableLog] (DWORD) to 1

To disable, set to 0 or delete the value.

[edit ]:Save the following text to a file, e.g FusionEnableLog.reg, in Windows Registry Editor Format:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion]
"EnableLog"=dword:00000001

Then run the file from windows explorer and ignore the warning about possible damage.

Michael Freidgeim
  • 26,542
  • 16
  • 152
  • 170
user32736
  • 10,221
  • 3
  • 18
  • 6
  • 4
    Not that the entry probably won't exist - you'll have to create it. At least, I did when I was about to answer this question just before the crash this morning :) – Jon Skeet Nov 01 '08 at 15:54
  • 4
    What does the ! mean? Key or value? What about 64 bits systems? – Bruno Martinez Jul 14 '09 at 15:21
  • 2
    this doesn't actually work. the value is ForceLog not EnableLog, and there is an additional step needed here (see: http://thepursuitofalife.com/getting-assembly-bind-failure-logging-to-work/) – Marchy Nov 16 '09 at 22:04
  • 49
    actually, this does work...you just need to run iisreset afterwords to get it to work. – Nick DeMayo Jun 22 '10 at 13:02
  • iisreset? Really? Why would you reset IIS to get Fusion bind logging to work? – Norman H Jul 08 '10 at 19:55
  • 4
    @Norman: Because this particular setting is used to make the Asp.Net errors show assembly binding error messages in the error pages, not to save the logs to file. @OP: +1. Edited to include a .reg file. The ! format is one I had never seen, except in the error message that sent me to this page looking for answers. – Brian Feb 08 '11 at 21:53
  • 2
    You don't need to reset IIS – just the relevant application pool. Or at least that was all I needed to do. – Kenny Evitt Jan 23 '15 at 16:54
  • what is Windows Registry Editor Format: ? – Shesha Mar 30 '16 at 05:36
  • 1
    Marchy's link should go to https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-1.1/e74a18c4(v=vs.71) – Ian Kemp Jul 04 '18 at 09:47
45

There's so much wrong with the Assembly Binding Log Viewer (FUSLOGVW.exe) that I decided to write an alternative viewer named Fusion++ and put it on GitHub. It uses the same mechanics internally but parses the logs for you. You don't have to care for any settings at all, not even log paths

You can get the latest release from here or via chocolatey (choco install fusionplusplus).

I hope you and some of the visitors in here can save some worthy lifetime minutes with it.

Fusion++

Waescher
  • 5,361
  • 3
  • 34
  • 51
21

The Fusion Log Settings Viewer changer script is bar none the best way to do this.

In ASP.NET, it has been tricky at times to get this to work correctly. This script works great and was listed on Scott Hanselman's Power Tool list as well. I've personally used it for years and its never let me down.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Adam Tuliper
  • 29,982
  • 4
  • 53
  • 71
16

Instead of using a ugly log file, you can also activate Fusion log via ETW/xperf by turning on the DotnetRuntime Private provider (Microsoft-Windows-DotNETRuntimePrivate) with GUID 763FD754-7086-4DFE-95EB-C01A46FAF4CA and the FusionKeyword keyword (0x4) on.

@echo off
echo Press a key when ready to start...
pause
echo .
echo ...Capturing...
echo .

"C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\xperf.exe" -on PROC_THREAD+LOADER+PROFILE -stackwalk Profile -buffersize 1024 -MaxFile 2048 -FileMode Circular -f Kernel.etl
"C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\xperf.exe" -start ClrSession -on Microsoft-Windows-DotNETRuntime:0x8118:0x5:'stack'+763FD754-7086-4DFE-95EB-C01A46FAF4CA:0x4:0x5 -f clr.etl -buffersize 1024

echo Press a key when you want to stop...
pause
pause
echo .
echo ...Stopping...
echo .

"C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\xperf.exe" -start ClrRundownSession -on Microsoft-Windows-DotNETRuntime:0x8118:0x5:'stack'+Microsoft-Windows-DotNETRuntimeRundown:0x118:0x5:'stack' -f clr_DCend.etl -buffersize 1024 

timeout /t 15

set XPERF_CreateNGenPdbs=1

"C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\xperf.exe" -stop ClrSession ClrRundownSession 
"C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\xperf.exe" -stop
"C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\xperf.exe" -merge kernel.etl clr.etl clr_DCend.etl Result.etl -compress
del kernel.etl
del clr.etl
del clr_DCend.etl

When you now open the ETL file in PerfView and look under the Events table, you can find the Fusion data:

Fusion events in PerfView

magicandre1981
  • 27,895
  • 5
  • 86
  • 127
  • @YuriBondarchuk this activates it on demand and you have more data in the ETL (other processes, fileversion data) so that you can give the files t other users and they can get MUCH more information compared to the normal fusion log – magicandre1981 Sep 17 '15 at 04:04
6

For those who are a bit lazy, I recommend running this as a bat file for when ever you want to enable it:

reg add "HKLM\Software\Microsoft\Fusion" /v EnableLog /t REG_DWORD /d 1 /f
reg add "HKLM\Software\Microsoft\Fusion" /v ForceLog /t REG_DWORD /d 1 /f
reg add "HKLM\Software\Microsoft\Fusion" /v LogFailures /t REG_DWORD /d 1 /f
reg add "HKLM\Software\Microsoft\Fusion" /v LogResourceBinds /t REG_DWORD /d 1 /f
reg add "HKLM\Software\Microsoft\Fusion" /v LogPath /t REG_SZ /d C:\FusionLog\

if not exist "C:\FusionLog\" mkdir C:\FusionLog
Igor Meszaros
  • 2,081
  • 2
  • 22
  • 46
4

Just a tiny bit of info that might help others; if you do something along the lines of searching all assemblies in some directory for classes that inherit/implement classes/interfaces, then make sure you clean out stale assemblies if you get this error pertaining to one of your own assemblies.

The scenario would be something like:

  1. Assembly A loads all assemblies in some folder
  2. Assembly B in this folder is stale, but references assembly C
  3. Assembly C exists, but namespaces, class names or some other detail might have changed in the time that has passed since assembly B became stale (in my case a namespace was changed through a refactoring process)

In short: A ---loads--> B (stale) ---references---> C

If this happens, the only telltale sign is the namespace and classname in the error message. Examine it closely. If you can't find it anywhere in your solution, you are likely trying to load a stale assembly.

andrerav
  • 404
  • 5
  • 14
4

Just in case you're wondering about the location of FusionLog.exe - You know you have it, but you cannot find it? I was looking for FUSLOVW in last few years over and over again. After move to .NET 4.5 number of version of FUSION LOG has exploded. Her are places where it can be found on your disk, depending on software which you have installed:

C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\x64

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\x64

C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64

C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools

C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin

Dikshit Kathuria
  • 1,182
  • 12
  • 15
3

If you already have logging enabled and you still get this error on Windows 7 64 bit, try this in IIS 7.5:

  1. Create a new application pool

  2. Go to the Advanced Settings of this application pool

  3. Set the Enable 32-Bit Application to True

  4. Point your web application to use this new pool

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Adam Mendoza
  • 5,419
  • 2
  • 25
  • 31
3

This is not an answer but a word of warning:

  • If you ever enable this logging, DO NOT FORGET TO DISABLE IT or you will regret it later.

I did forget, and I ended up with several GB of small log files with HTM extension in C:\Windows\System32\config\systemprofile\AppData\Local\Microsoft\Windows\INetCache\IE folder — it was apparently logging all assembly bindings from applications running under NT AUTHORITY\SYSTEM account.

The number of files was greater than 3 million and neither Total Commander nor Windows Explorer could display the contents or folder size without hanging.

After disabling logging and a reboot for good measure, I ran the deletion from command prompt.

It took more than 15 minutes to delete all the files on a Samsung 970 Pro SSD which was showing 100% disk usage all the time — my high-end PC workstation was brought down to its knees by this delete operation and remained only partially responsive until it finished.

Igor Levicki
  • 1,017
  • 10
  • 17
-2

In my case helped type disk name in lower case

Wrong - C:\someFolder

Correct - c:\someFolder

Vlad
  • 1,017
  • 1
  • 15
  • 18