ChatGPT解决这个技术问题 Extra ChatGPT

How to enable assembly bind failure logging (Fusion) in .NET

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

If anybody cares, to use fusion logger (fuslogvw.exe) read this article: msdn.microsoft.com/en-us/library/e74a18c4(v=VS.100).aspx it tells you where to download it and other info.
@Will - thanks for sharing! As a bonus - make sure you run fuslogvw.exe as an administrator to avoid any rights issues.
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.
@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.
@Will Certainly, but the answer you link to does not cover any of that.

H
Hakan Yildizhan

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.

https://i.stack.imgur.com/hcled.jpg


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.
Been reported by some that registry change does not take right away. Have you tried turning Fusion logging on then rebooting?
You need to restart whatever program it is you're running for it to read those registry settings
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.
To turn on/off logging handy, I've created .reg files, which are based on Gary Kindel's answer: enabling and disabling.
P
Phil

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.)


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.
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.
Run as Administrator was required in my case, otherwise all options were disabled.
Note: create the folder as Admin!
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...)
S
Samuel Jack

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".


Those buttons are disabled for me - why?
@Tim, not seen that before - could it be to do with Admin privileges? It is HKEY_LOCAL_MACHINE that is being modified after all.
"Settings, Log bind failures" was enough to find my problem.
Make sure the folder allows write access. UAC and c:\logs do not play nice with the fusion log
Just as a note, if the buttons are disabled, re-run fusion log viewer with admin privileges.
T
Tereza Tomcova

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

Thanks! I've allowed myself to put your commands into this gist. And I added creation of the c:\FusionLog dir so that people don't forget that ;-)
Command line rules! I could quickly replay this using the best invented so far code reusability technology called "cut and paste". Thanks.
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.
M
Michael Freidgeim

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.


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 :)
What does the ! mean? Key or value? What about 64 bits systems?
actually, this does work...you just need to run iisreset afterwords to get it to work.
@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.
You don't need to reset IIS – just the relevant application pool. Or at least that was all I needed to do.
W
Waescher

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.

https://i.stack.imgur.com/2uOEO.png


P
Peter Mortensen

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.


ps MAKE SURE you disable it after running or this folder could get quite large
this is why I use ETW, to only log data if I really need them, not all the time in an ugly large log file.
m
magicandre1981

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:

https://i.stack.imgur.com/eccjZ.png


@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
I
Igor Meszaros

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

a
andrerav

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:

Assembly A loads all assemblies in some folder Assembly B in this folder is stale, but references assembly C 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.


P
Peter Mortensen

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

Create a new application pool Go to the Advanced Settings of this application pool Set the Enable 32-Bit Application to True Point your web application to use this new pool


D
Dikshit Kathuria

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


V
Vlad

In my case helped type disk name in lower case

Wrong - C:\someFolder

Correct - c:\someFolder


How is this related at all to the question?
I used this as value for LogPath parameter in registry. But now I think the problem was not in CASE but in wrong letter C != С