0

我有一个 Windows Phone 8 类库。在该类库中,我使用了 System.ServiceModel。当从 Windows Phone 8 应用程序中使用时,类库运行良好。

我有一个单元测试项目。如果我尝试使用单元测试项目来测试类库中的方法,我会得到一个 FileNotFoundExcaption:

{"Could not load file or assembly 'System.ServiceModel, 
Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 
or one of its dependencies. The system cannot find the file 
specified.":"System.ServiceModel, Version=2.0.5.0, Culture=neutral, 
PublicKeyToken=31bf3856ad364e35"}

我尝试过使用绑定重定向,但是因为两个 System.Service 模型程序集有不同的 publicKeyTokens 似乎不起作用。

这可能吗?

完整的融合日志是:

=== Pre-bind state information ===
LOG: User = MACHINENAME\Simon
LOG: DisplayName = System.ServiceModel, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///c:/[...]/PhoneClassLibraryReferenceTest/PhoneClassLibraryTest/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : PhoneClassLibraryReferenceTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\vstest.executionengine.x86.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.ServiceModel, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///c:/[...]/PhoneClassLibraryReferenceTest/PhoneClassLibraryTest/bin/Debug/System.ServiceModel.DLL.
LOG: Attempting download of new URL file:///c:/[...]/PhoneClassLibraryReferenceTest/PhoneClassLibraryTest/bin/Debug/System.ServiceModel/System.ServiceModel.DLL.
LOG: Attempting download of new URL file:///c:/[...]/PhoneClassLibraryReferenceTest/PhoneClassLibraryTest/bin/Debug/System.ServiceModel.EXE.
LOG: Attempting download of new URL file:///c:/[...]/PhoneClassLibraryReferenceTest/PhoneClassLibraryTest/bin/Debug/System.ServiceModel/System.ServiceModel.EXE.
4

1 回答 1

1

解决方案是安装 Visual Studio 2012 更新 2,并使用 Windows Phone 8 测试项目。

这样,您的测试将通过模拟器运行并针对 System.ServiceModel 程序集的正确版本。

这篇博文描述了如何开始使用 Windows Phone 8 单元测试项目

于 2013-06-18T10:37:07.177 回答