我如何在.NET中启用程序集绑定失败日志记录(融合)?


当前回答

融合日志设置查看器更改脚本是做到这一点的最好方法。

在ASP。NET中,有时要使它正确工作是很棘手的。这个脚本工作得很好,也被列入了Scott Hanselman的Power Tool列表。我个人已经使用它很多年了,它从来没有让我失望过。

其他回答

您可以以管理员身份运行此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

这个要禁用:

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

您也可以通过ETW/xperf通过GUID 763FD754-7086-4DFE-95EB-C01A46FAF4CA和FusionKeyword关键字(0x4)打开dotnetruntimeprivate提供者(Microsoft-Windows-DotNETRuntimePrivate)来激活Fusion日志。

@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

当你现在在PerfView中打开ETL文件并在事件表下查看时,你可以找到Fusion数据:

只是一点点可能会帮助别人的信息;如果您在某个目录中搜索继承/实现类/接口的类的所有程序集,那么如果您得到与您自己的某个程序集相关的此错误,请确保您清除了过时的程序集。

场景是这样的:

程序集A装入某个文件夹中的所有程序集 此文件夹中的程序集B已过期,但引用程序集C 程序集C存在,但是名称空间、类名或其他一些细节可能在程序集B失效后发生了变化(在我的例子中,名称空间是通过重构过程改变的)。

简而言之:——加载> B(过期)——引用——> C

如果发生这种情况,唯一的迹象是错误消息中的名称空间和类名。仔细检查。如果您在解决方案中到处都找不到它,那么您可能正在尝试加载一个陈旧的程序集。

在我的例子中,帮助键入小写的磁盘名称

错误- C:\someFolder

正确- c:\someFolder

如果你已经启用了日志记录,在Windows 7 64位上仍然会得到这个错误,在iis7.5中尝试一下:

创建一个新的应用程序池 进入该应用池的高级设置 将启用32位应用程序设置为True 让您的web应用程序使用这个新池