Using Fusion Logs to Debug .NET Assembly Binding Issues

A fusion log can contain very useful debugging information when you experience a failure to bind to an assembly.  FileNotFoundException, FileLoadException, and BadImageFormatException are all exceptions that commonly result from this failure to bind.  According to Junfeng Zhang's blog - because the assembly binding rules are so different than traditional LoadLibrary binds, Microsoft decided to add logging information throughout the binding process.  As as result, you simply need to tell FUSLOGVW.exe where to store the logs, and then they will be available for you to examine.  There are a couple ways to do this:

 

  1. The first way to tell FUSLOGVW (the name of the fusion logging utility) where to store the logs is through it's UI.  You can generally find FUSLOGVW is in this location:  C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin as a part of the windows SDK.   Once you launch FUSLOGVW, select the Settings button, and then configure the settings as follows (of course, you can specify a different path):
    FUSLOGSettings.png
    Once you have completed these settings, you should ensure the "Custom" log location is selected on the main UI.  This tells the utility that you are going to store the logs in a particular place on disk.
  2. The second method to enable these settings is to do it directly through the registry.  If you have never used a fusion log before, you will need to create two registry keys (to always log all binds), all at HKLM\Software\Microsoft\Fusion\  The two keys are:

    REG_DWORD  -  ForceLog  -  Set this equal to 1 to log all assembly binds.
    REG_SZ  -  Logpath  -  This is the path to the directory you want to store your logs in.

 

Once you have told FUSLOGVW where to store the logs, make sure you restart the process you are debugging, otherwise the settings won't take effect.  Upon restarting and running your application, you can go to the directory the logs are being stored, and take a look at how your applications dependencies were satisfied.  For example, below is an example Fusion log for the binding of the NationalInstruments.Common assembly.  As you may know, the latest version of NationalInstruments.Common on a machine installs a policy file that redirects all requests for NationalInstruments.Common to the latest version of NationalInstruments.Common installed in the GAC.  The following log demonstrates that in action, with the important sections highlighted in red:

 

 

Example Good Fusion Log

** Assembly Binder Log Entry  (2/10/2009 @ 7:30:03 AM) **

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under executable  D:\Development\VS2008\Projects\TestMissingPolicyFile\TestMissingPolicyFile\bin\ Debug\TestMissingPolicyFile.vshost.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: User = 406Z28\Beer
LOG: DisplayName = NationalInstruments.Common, Version=8.5.35.147, Culture=neutral, PublicKeyToken=18cbae0f9955702a
(Fully-specified)
LOG: Appbase = D:/Development/VS2008/Projects/TestMissingPolicyFile/TestMissingPolicyFile/bin/ Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : NationalInstruments.DAQmx, Version=8.7.35.201, Culture=neutral, PublicKeyToken=18cbae0f9955702a.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Publisher policy file is found at C:\WINDOWS\assembly\GAC_MSIL\policy.8.5.NationalInstruments.Common\8.6.35.122__ 18cbae0f9955702a\NationalInstruments.Common.config.
LOG: Publisher policy file redirect is found: 8.5.35.147 redirected to 8.6.35.122.
LOG: ProcessorArchitecture is locked to MSIL.
LOG: Post-policy reference: NationalInstruments.Common, Version=8.6.35.122, Culture=neutral, PublicKeyToken=18cbae0f9955702a, processorArchitecture=MSIL
LOG: Binding succeeds. Returns assembly from C:\WINDOWS\assembly\GAC_MSIL\NationalInstruments.Common\8.6.35.122__18cbae0f995 5702a\NationalInstruments.Common.dll.
LOG: Assembly is loaded in default load context.

 

By slightly modifying the policy file, I generated a fusion log where the CLR could not find the referenced assembly, and so generated a FileNotFoundException.  This allows you to see the search paths that are used when looking for an assembly:

 

Example Fusion Log With Failure

** Assembly Binder Log Entry  (2/10/2009 @ 8:33:24 AM) **

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under executable  D:\Development\VS2008\Projects\TestMissingPolicyFile\TestMissingPolicyFile\bin\ Debug\TestMissingPolicyFile.vshost.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: User = 406Z28\Beer
LOG: DisplayName = NationalInstruments.Common, Version=8.5.35.147, Culture=neutral, PublicKeyToken=18cbae0f9955702a
  (Fully-specified)
LOG: Appbase = D:/Development/VS2008/Projects/TestMissingPolicyFile/TestMissingPolicyFile/bin/ Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : NationalInstruments.DAQmx, Version=8.7.35.201, Culture=neutral, PublicKeyToken=18cbae0f9955702a.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Publisher policy file is found at C:\WINDOWS\assembly\GAC_MSIL\policy.8.5.NationalInstruments.Common\8.6.35.122__ 18cbae0f9955702a\NationalInstruments.Common.config.
LOG: Publisher policy file redirect is found: 8.5.35.147 redirected to 8.6.35.123.
LOG: ProcessorArchitecture is locked to MSIL.
LOG: Post-policy reference: NationalInstruments.Common, Version=8.6.35.123, Culture=neutral, PublicKeyToken=18cbae0f9955702a, processorArchitecture=MSIL
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL D:/Development/VS2008/Projects/TestMissingPolicyFile/TestMissingPolicyFile/bin/ Debug/NationalInstruments.Common.DLL.
LOG: Attempting download of new URL D:/Development/VS2008/Projects/TestMissingPolicyFile/TestMissingPolicyFile/bin/ Debug/NationalInstruments.Common/NationalInstruments.Common.DLL.
LOG: Attempting download of new URL D:/Development/VS2008/Projects/TestMissingPolicyFile/TestMissingPolicyFile/bin/ Debug/NationalInstruments.Common.EXE.
LOG: Attempting download of new URL D:/Development/VS2008/Projects/TestMissingPolicyFile/TestMissingPolicyFile/bin/ Debug/NationalInstruments.Common/NationalInstruments.Common.EXE.
LOG: All probing URLs attempted and failed.

 

For more information on using the FUSLOGVW utility, check out Suzanne Cook's blog entries here and here.

 

Nick



from: http://decibel.ni.com/content/people/nickb/blog/2009/06/16/using-fusion-logs-to-debug-net-assembly-binding-issues

转载于:https://www.cnblogs.com/joe-yang/archive/2009/09/27/1574882.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值