c# - 为什么在为 Silverlight 5 应用程序添加编码 UI 支持时 System.Core 加载失败?

标签 c# .net silverlight ui-automation coded-ui-tests

我遇到了以下问题:

尝试添加对为 Silverlight 5 应用程序创建编码 UI 测试的支持 ([MSDN][1])。第一步是在 Silverlight 5 项目中引用程序集 Microsoft.VisualStudio.TestTools.UITest.Extension.SilverlightUIAutomationHelper.dll。不幸的是,在添加引用后,项目停止编译并出现许多类似的错误:

>

 Error  25  Cannot resolve reference assemblies. Please check the reference assemblies. Could not load file or assembly 'System.Core, Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) ....\ErrorReportDialog.xaml


Looks like System.Core 5.0.5.0 fails to load, okay, debugging assemblies loading with Fuslogw produces two interesting logs:

First log:

> Assembly Binder Log Entry  (04.03.2013 @ 14:07:49)
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:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
A detailed error log follows. 
=== Pre-bind state information ===
LOG: DisplayName = System.Core, Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
 (Fully-specified)
LOG: Appbase = file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MSBuild.exe
Calling assembly : System.Windows, Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e.
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.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: Post-policy reference: System.Core, Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
LOG: Binding succeeds. Returns assembly from C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v5.0\System.Core.dll.
LOG: Assembly is loaded in LoadFrom load context.

Looks like System.Core, Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e loads succesfully.

But second log entry produces the following error:

> Assembly Binder Log Entry  (04.03.2013 @ 14:07:49)
The operation failed.
Bind result: hr = 0x80131040. No description available.
Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
A detailed error log follows. 
Pre-bind state information
LOG: DisplayName = System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
 (Fully-specified)
LOG: Appbase = file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MSBuild.exe
Calling assembly : Microsoft.VisualStudio.TestTools.UITest.Extension.SilverlightUIAutomationHelper, Version=10.0.30319.381, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.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: Redirect found in application configuration file: 2.0.5.0 redirected to 5.0.5.0.
LOG: Post-policy reference: System.Core, Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
LOG: The same bind was seen before, and was failed with hr = 0x80131040.
ERR: Unrecoverable error occurred during pre-download check (hr = 0x80131040).

看起来像 Microsoft.VisualStudio.TestTools.UITest.Extension.SilverlightUIAutomationHelper.dll 试图加载 System.Core,Version=2.0.5.0,Culture=neutral,PublicKeyToken=7cec85d7bea7798e,但被重定向到 System.Core,Version= 5.0.5.0,Culture=neutral,PublicKeyToken=7cec85d7bea7798e(已从第一个日志加载),仍然加载失败。

Can anyone provide some insight on how to further debug this problem? I'm compiling Silverlight projects for AnyCpu platform.


  [1]: http://msdn.microsoft.com/en-us/library/gg413374.aspx

最佳答案

要确认 SilverlightUIAuthomationHelper 所需的 System.Core 版本,请执行以下操作:

  1. 在磁盘上找到引用的 SilverlightUIAuthomationHelper dll。
  2. 将其加载到任何反汇编器/反射器中 - 例如 dotPeek 或 Reflector。
  3. 检查引用程序集的版本 - 在您的 SilverlightUIAuthomationHelper 版本中,System.Core 必须是 2.0.5.0

可能的解决方案:

  1. 将 SilverlightUIAuthomationHelper 更新为引用新 System.Core dll(版本 5.0.5.0)的新版本(Hans Passant 评论中的链接)
  2. 因为 fuslogvw 说从 2.0.5.0 到 5.0.5.0 的重定向位于应用程序配置文件中 - 尝试找到并删除此重定向 (details here)。但是其他东西很可能会坏掉。

关于c# - 为什么在为 Silverlight 5 应用程序添加编码 UI 支持时 System.Core 加载失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15201164/

相关文章:

c# - 开始使用带有证书身份验证的 WCF 路由 - 陷入 XML hell

C# For 循环困惑

c# - 查找控件的直接祖先/父级

.net - %2b 导致 IIS Hosted Angular 返回 404

c# - 通过 header 验证文件格式的库

silverlight - Silverlight Loaded 事件如何工作?

c# - Azure 表存储返回 400 错误请求

.net - 如何最好地使用文件版本和程序集版本?

silverlight - 显示 Silverlight 生成的消息

javascript - 使用 Ajax 或 Silverlight 调用 Web 服务?哪个表现最好?