Could not load file or assembly 'System.Web.Http

使用FusLogVw

https://stackoverflow.com/questions/4469929/could-not-load-file-or-assembly-or-one-of-its-dependencies?page=1&tab=votes#tab-top

You can use FusLogVw to find out who is loading the old assemblies, just define a path for the log, and run your solution, then check (in FusLogvw) the first line where the Unity assembly is loaded, double click it and see the calling assembly, and here you go.

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2017\Visual Studio Tools\Developer Command Prompt for VS 2017 (2)  

 

 

如何使用

https://stackoverflow.com/questions/255669/how-to-enable-assembly-bind-failure-logging-fusion-in-net/3256753#3256753

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

 

实例

在页面中搜索application对应的编码,发现存在临时文件,需要将这个文件夹删除C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\lisa_60_dev_cmsweb11\931fe700\6226aa26

将application下面所有的文件夹以及文件删除,然后使用visual studio重新编译项目

 

*** Assembly Binder Log Entry  (2018/10/31 @ 13:44:32) ***

The operation failed.
Bind result: hr = 0x80131040. No description available.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  c:\windows\system32\inetsrv\w3wp.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = System.Net.Http.Formatting
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: System.Net.Http.Formatting | Domain ID: 4
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/clu/source/repos/Edenred/LISA_6.0.0.0/Kentico11/LISA.Kentico11/
LOG: Initial PrivatePath = C:\Users\clu\source\repos\Edenred\LISA_6.0.0.0\Kentico11\LISA.Kentico11\bin
LOG: Dynamic Base = C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\lisa_60_dev_cmsweb11\931fe700
LOG: Cache Base = C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\lisa_60_dev_cmsweb11\931fe700
LOG: AppName = 6226aa26
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\clu\source\repos\Edenred\LISA_6.0.0.0\Kentico11\LISA.Kentico11\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/lisa_60_dev_cmsweb11/931fe700/6226aa26/System.Net.Http.Formatting.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/lisa_60_dev_cmsweb11/931fe700/6226aa26/System.Net.Http.Formatting/System.Net.Http.Formatting.DLL.
LOG: Attempting download of new URL file:///C:/Users/clu/source/repos/Edenred/LISA_6.0.0.0/Kentico11/LISA.Kentico11/bin/System.Net.Http.Formatting.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Users\clu\source\repos\Edenred\LISA_6.0.0.0\Kentico11\LISA.Kentico11\bin\System.Net.Http.Formatting.dll
LOG: Entering download cache setup phase.
LOG: Assembly Name is: System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: A partially-specified assembly bind succeeded from the application directory. Need to re-apply policy.
LOG: Using application configuration file: C:\Users\clu\source\repos\Edenred\LISA_6.0.0.0\Kentico11\LISA.Kentico11\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 5.2.3.0 redirected to 5.2.6.0.
LOG: Post-policy reference: System.Net.Http.Formatting, Version=5.2.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: GAC Lookup was unsuccessful.
LOG: The post-policy assembly reference requires probing again.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/lisa_60_dev_cmsweb11/931fe700/6226aa26/System.Net.Http.Formatting.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/lisa_60_dev_cmsweb11/931fe700/6226aa26/System.Net.Http.Formatting/System.Net.Http.Formatting.DLL.
LOG: Attempting download of new URL file:///C:/Users/clu/source/repos/Edenred/LISA_6.0.0.0/Kentico11/LISA.Kentico11/bin/System.Net.Http.Formatting.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Users\clu\source\repos\Edenred\LISA_6.0.0.0\Kentico11\LISA.Kentico11\bin\System.Net.Http.Formatting.dll
LOG: Entering download cache setup phase.
LOG: Assembly Name is: System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
WRN: Comparing the assembly name resulted in the mismatch: Build Number
ERR: The assembly reference did not match the assembly definition found.
ERR: Setup failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

*** Assembly Binder Log Entry  (2018/10/31 @ 13:44:32) ***

The operation failed.
Bind result: hr = 0x80131040. No description available.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  c:\windows\system32\inetsrv\w3wp.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = System.Net.Http.Formatting
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: System.Net.Http.Formatting | Domain ID: 4
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/clu/source/repos/Edenred/LISA_6.0.0.0/Kentico11/LISA.Kentico11/
LOG: Initial PrivatePath = C:\Users\clu\source\repos\Edenred\LISA_6.0.0.0\Kentico11\LISA.Kentico11\bin
LOG: Dynamic Base = C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\lisa_60_dev_cmsweb11\931fe700
LOG: Cache Base = C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\lisa_60_dev_cmsweb11\931fe700
LOG: AppName = 6226aa26
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\clu\source\repos\Edenred\LISA_6.0.0.0\Kentico11\LISA.Kentico11\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/lisa_60_dev_cmsweb11/931fe700/6226aa26/System.Net.Http.Formatting.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/lisa_60_dev_cmsweb11/931fe700/6226aa26/System.Net.Http.Formatting/System.Net.Http.Formatting.DLL.
LOG: Attempting download of new URL file:///C:/Users/clu/source/repos/Edenred/LISA_6.0.0.0/Kentico11/LISA.Kentico11/bin/System.Net.Http.Formatting.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Users\clu\source\repos\Edenred\LISA_6.0.0.0\Kentico11\LISA.Kentico11\bin\System.Net.Http.Formatting.dll
LOG: Entering download cache setup phase.
LOG: Assembly Name is: System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: A partially-specified assembly bind succeeded from the application directory. Need to re-apply policy.
LOG: Using application configuration file: C:\Users\clu\source\repos\Edenred\LISA_6.0.0.0\Kentico11\LISA.Kentico11\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 5.2.3.0 redirected to 5.2.6.0.
LOG: Post-policy reference: System.Net.Http.Formatting, Version=5.2.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: GAC Lookup was unsuccessful.
LOG: The post-policy assembly reference requires probing again.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/lisa_60_dev_cmsweb11/931fe700/6226aa26/System.Net.Http.Formatting.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/lisa_60_dev_cmsweb11/931fe700/6226aa26/System.Net.Http.Formatting/System.Net.Http.Formatting.DLL.
LOG: Attempting download of new URL file:///C:/Users/clu/source/repos/Edenred/LISA_6.0.0.0/Kentico11/LISA.Kentico11/bin/System.Net.Http.Formatting.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Users\clu\source\repos\Edenred\LISA_6.0.0.0\Kentico11\LISA.Kentico11\bin\System.Net.Http.Formatting.dll
LOG: Entering download cache setup phase.
LOG: Assembly Name is: System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
WRN: Comparing the assembly name resulted in the mismatch: Build Number
ERR: The assembly reference did not match the assembly definition found.
ERR: Setup failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.