为什么在为Silverlight 5应用程序添加Coded UI支持时,System.Core无法加载?

26
我有以下问题:
尝试为Silverlight 5应用程序([MSDN][1])添加创建编码UI测试的支持。第一步是在Silverlight 5项目中引用Microsoft.VisualStudio.TestTools.UITest.Extension.SilverlightUIAutomationHelper.dll程序集。不幸的是,在添加引用后,项目停止编译,并出现许多类似的错误:
[1]: https://msdn.microsoft.com/en-us/library/ff921103(v=vs.110).aspx

>

 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

2
System.Core,Version=2.0.5.0 当然是问题所在。这是旧版本的程序集,在之前的 Silverlight 版本中使用。他们没有在 VS2012 中完成它,请查看此博客文章 - Hans Passant
我已经使用VS2010进行了检查 - 机器配置文件中的重定向在那里不起作用。它会产生一个错误,无法找到System.Core 2.0.5.0,因为项目引用了5.0.5.0。奇怪的是,我们使用的是相同版本的.Net Framework本身。 - Cortlendt
@HansPassant:你觉得把那个链接作为答案发布是个好主意吗?我知道这不是完美的解决方案,但我认为这可能是最好的选择。 - Jeff Yates
1个回答

1

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

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

可能的解决方案:

  1. 将SilverlightUIAuthomationHelper更新到新版本(Hans Passant评论中的链接),该版本引用了新的System.Core dll(版本5.0.5.0)。
  2. 因为fuslogvw说重定向从2.0.5.0到5.0.5.0位于应用程序配置文件中 - 尝试查找并删除此重定向(详情在此处)。但很可能会导致其他问题。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接