10

我有一个 .NET 4.5 应用程序,可以在大多数环境中正常工作和运行;但是,应用程序的一个区域会在某些客户端机器上引发运行时程序集引用错误:

Could not load file or assembly 'System.Xml.Linq, Version 4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The file cannot be accessed by the system. (Exception from HRESULT: 0x80070780)

我运行了融合日志,有趣的是,这个程序集似乎被加载了两次,一次用于版本 4.0.0.0,然后在加载 Newtonsoft.Json 版本 6.0.8 时用于版本 3.5.0.0。第一次加载有效,第二次加载是绑定错误的来源。

这是成功绑定 4.0.0.0 的 Fusion 日志:

<meta http-equiv="Content-Type" content="charset=unicode-1-1-utf-8"><!-- saved from url=(0015)assemblybinder: --><html><pre>
*** Assembly Binder Log Entry  (1/16/2017 @ 12:40:06 PM) ***

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

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Users\<user>\AppData\Local\Apps\MyApplicationPath\MyApplication.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL
 (Fully-specified)
LOG: Appbase = file:///C:/Users/<user>/AppData/Local/Apps/MyApplicationPath/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MyApplication.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\<user>\AppData\Local\Apps\MyApplicationPath\MyApplication.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Found assembly by looking in the GAC.
LOG: Binding succeeds. Returns assembly from C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll.
LOG: Assembly is loaded in default load context.

</pre></html>

这是不成功的 3.5.0.0 绑定:

<meta http-equiv="Content-Type" content="charset=unicode-1-1-utf-8"><!-- saved from url=(0015)assemblybinder: --><html><pre>
*** Assembly Binder Log Entry  (1/16/2017 @ 12:41:12 PM) ***

The operation failed.
Bind result: hr = 0x80070780. The file cannot be accessed by the system.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Users\<user>\AppData\Local\Apps\MyApplicationPath\MyApplication.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
 (Fully-specified)
LOG: Appbase = file:///C:/Users/<user>/AppData/Local/Apps/MyApplicationPath/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MyApplication.exe
Calling assembly : Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\<user>\AppData\Local\Apps\MyApplicationPath\MyApplication.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Version redirect found in framework config: 3.5.0.0 redirected to 4.0.0.0.
LOG: Post-policy reference: System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
LOG: Binding succeeds. Returns assembly from C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll.
LOG: Assembly is loaded in default load context.
ERR: Unrecoverable error occurred during pre-download check (hr = 0x80070780).

</pre></html>

对我来说真正没有意义的是它正在从相同的确切位置加载程序集,并且第二次无法正常工作。我认为这可能是由于 GAC 程序集上的某种锁定,但在工作环境中检查 Fusion 日志后,日志文件是相同的,只是没有最后的错误行,所以不是这样。

同样有趣的是,这个问题似乎只发生在 Windows 10 机器上,而不是所有 Windows 10 机器上。它似乎也不限于升级或全新的 Win10 安装;它发生在两者上。

我尝试了很多方法来解决这个问题,包括:

  • .NET 修复
  • 完全删除并重新安装 .NET
  • 清除临时 ASP.NET 文件
  • 将程序集绑定重定向/探测添加到应用程序配置文件以手动指向引用应用程序的 bin 文件夹或根文件夹的文件(对引用程序集的 3.5、4.0 和 4.5 版本进行了尝试。
  • 使用 Windows 10 修复功能重新安装操作系统(并保留文件)
  • 确保所需的程序集位于 GAC 中(在新的 GAC 位置)
  • 使用最新版本的 Newtonsoft.Json 重新发布应用程序。
  • 创建一个引用 Newtonsoft.Json 和相同 System.Xml.Linq 程序集的基本测试应用程序(在坏机器上工作)

我似乎用完了选项,不幸的是,我无法得到比“不可恢复的错误”更具体的错误,所以我不知道还能去哪里找。任何帮助是极大的赞赏!

4

0 回答 0