Debug .NET assembly binding aka Find what dll is u

2019-02-15 18:17发布

问题:

We're having some mystery version mismatches on our referenced dll's loaded at runtime.

Errors like:

Could not load file or assembly X or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Is there any way to debug the assembly binding.

In other words, how can I know the following details about loaded assemblies:

  • Version
  • Location
  • Who/What caused the loading (my code, another .dll, ...)
  • Well, just about everything else there is to know...

回答1:

The Assembly Binding Log Viewer (aka Fusion Log Viewer, fuslogvw.exe) shows useful data for these sorts of issues such as:

  • What process is trying to load an assembly
  • The full name of the assembly (version, culture, public key token)
  • The assembly that's causing the load
  • Which paths were probed for the assembly

You can log all binds or just bind failures.

fuslogvw.exe should be accessible directly from any VS command prompt.



回答2:

Totally agree with Chris, Assembly Binding Log Viewer should give you all information you need. In addition you could also use WinDbg + SOS.dll. Mostly it's used for debugging but can be quite useful in some other cases when you need to know as much information as possible. The only problem that could stop you is that it doesn't have nice UI like VS debugger :)

Good luck!