C# 如何在 .NET 中启用程序集绑定失败日志记录 (Fusion)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/255669/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to enable assembly bind failure logging (Fusion) in .NET
提问by user32736
How do I enable assembly bind failure logging (Fusion) in .NET?
如何在 .NET 中启用程序集绑定失败日志记录 (Fusion)?
回答by user32736
Set the following registry value:
设置以下注册表值:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion!EnableLog] (DWORD) to 1
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion!EnableLog] (DWORD) 到 1
To disable, set to 0 or delete the value.
要禁用,请设置为 0 或删除该值。
[edit ]:Save the following text to a file, e.g FusionEnableLog.reg, in Windows Registry Editor Format:
[编辑]:以 Windows 注册表编辑器格式将以下文本保存到文件中,例如 FusionEnableLog.reg:
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.
然后从 Windows 资源管理器运行该文件并忽略有关可能损坏的警告。
回答by Gary Kindel
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 backslashafter 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.
您需要重新启动正在运行的程序以强制它读取这些注册表设置。
BTW, don't forget to turn off fusion logging off when not needed.
顺便说一句,不要忘记在不需要时关闭融合注销。
回答by Samuel Hyman
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".
如果您的机器上安装了 Windows SDK,您将在 Microsoft SDK\Tools 下找到“Fusion Log Viewer”(只需在 Vista 或 Windows 7/8 的开始菜单中键入“Fusion”)。启动它,单击“设置”按钮,然后选择“记录绑定失败”或“记录所有绑定”。
If these buttons are disabled, go back to the start menu, right-click the Log Viewer, and select "Run as Administrator".
如果这些按钮被禁用,请返回开始菜单,右键单击日志查看器,然后选择“以管理员身份运行”。
回答by Mike Goatly
I usually use the Fusion Log Viewer (Fuslogvw.exefrom a Visual Studio command promptor Fusion Log Viewer from the start menu) - my standard setup is:
我通常使用 Fusion Log Viewer(来自Visual Studio 命令提示符的Fuslogvw.exe或来自开始菜单的 Fusion Log Viewer) - 我的标准设置是:
- Open Fusion Log Viewer as administrator
- Click settings
- Check the Enable custom log pathcheckbox
- 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 diskjust to make sure things are working right)
- Click OK
- Set the log location option to Custom
- 以管理员身份打开 Fusion Log Viewer
- 点击设置
- 选中启用自定义日志路径复选框
- 输入您希望日志写入的位置,例如,
c:\FusionLogs
(重要提示:确保您已在文件系统中实际创建了此文件夹。) - 确保启用了正确的日志记录级别(我有时只是选择Log all binds to disk以确保一切正常)
- 单击确定
- 将日志位置选项设置为自定义
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.)
(我刚刚在一个类似的问题上发布了这个 - 我认为它在这里也很相关。)
回答by Adam Tuliper - MSFT
The Fusion Log Settings Viewer changer scriptis 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 listas well. I've personally used it for years and its never let me down.
在ASP.NET 中,有时很难让它正常工作。该脚本运行良好,也列在Scott Hanselman 的 Power Tool 列表中。我个人使用它多年,它从未让我失望。
回答by Adam Mendoza
If you already have logging enabled and you still get this error on Windows 7 64 bit, try this in IIS 7.5:
如果您已启用日志记录,但在 64 位 Windows 7 上仍然出现此错误,请在 IIS 7.5 中尝试此操作:
Create a new application pool
Go to the Advanced Settings of this application pool
Set the Enable 32-Bit Applicationto True
Point your web application to use this new pool
创建新的应用程序池
转到此应用程序池的高级设置
将启用 32 位应用程序设置为True
指向您的 Web 应用程序以使用此新池
回答by 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)
- 程序集 A 加载某个文件夹中的所有程序集
- 此文件夹中的程序集 B 已过时,但引用了程序集 C
- 程序集 C 存在,但名称空间、类名或其他一些细节可能在程序集 B 变得陈旧后过去的时间里发生了变化(在我的情况下,名称空间通过重构过程发生了变化)
In short: A ---loads--> B (stale) ---references---> C
简而言之: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.
如果发生这种情况,唯一的标志是错误消息中的命名空间和类名。仔细检查一下。如果您在解决方案中的任何地方都找不到它,您可能正在尝试加载一个陈旧的程序集。
回答by magicandre1981
Instead of using a ugly log file, you can also activate Fusion log via ETW/xperfby turning on the DotnetRuntime Private provider (Microsoft-Windows-DotNETRuntimePrivate
) with GUID 763FD754-7086-4DFE-95EB-C01A46FAF4CA
and the FusionKeyword
keyword (0x4) on.
除了使用丑陋的日志文件,您还可以通过ETW/xperf激活 Fusion 日志,方法是打开Microsoft-Windows-DotNETRuntimePrivate
带有 GUID763FD754-7086-4DFE-95EB-C01A46FAF4CA
和FusionKeyword
关键字 (0x4)的 DotnetRuntime Private 提供程序 ( ) 。
@echo off
echo Press a key when ready to start...
pause
echo .
echo ...Capturing...
echo .
"C:\Program Files (x86)\Windows Kits.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.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.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.1\Windows Performance Toolkit\xperf.exe" -stop ClrSession ClrRundownSession
"C:\Program Files (x86)\Windows Kits.1\Windows Performance Toolkit\xperf.exe" -stop
"C:\Program Files (x86)\Windows Kits.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 PerfViewand look under the Events table, you can find the Fusion data:
当您现在在PerfView 中打开 ETL 文件并查看 Events 表下时,您可以找到 Fusion 数据:
回答by Tereza Tomcova
You can run this Powershell script as administrator to enable FL:
您可以以管理员身份运行此 Powershell 脚本以启用 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
回答by 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:
以防万一您想知道 FusionLog.exe 的位置 - 您知道您拥有它,但找不到它?在过去的几年里,我一遍又一遍地寻找 FUSLOVW。迁移到 .NET 4.5 后,FUSION LOG 的版本数量激增。根据您安装的软件,可以在磁盘上找到它的位置:
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\x64
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\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.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.0A\bin\NETFX 4.0 工具
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 工具
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin