我的Windows Phone 7项目中的一个NUnit测试因以下错误而失败:
Error 4 Test 'MyProject.Tests.Unit.Service.TaskServiceTests.Save_CallsWebService_WhenCalledWithTaskAndSession' failed: System.IO.FileNotFoundException : Could not load file or assembly 'System.Runtime.Serialization, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.
at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract(JsonContract contract)
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract(Type objectType) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\DefaultContractResolver.cs:line 279
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\DefaultContractResolver.cs:line 545
at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\DefaultContractResolver.cs:line 188
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetContractSafe(Object value) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs:line 84
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs:line 67
at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\JsonSerializer.cs:line 451
at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Formatting formatting, JsonSerializerSettings settings) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\JsonConvert.cs:line 591
at Newtonsoft.Json.JsonConvert.SerializeObject(Object value) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\JsonConvert.cs:line 528
at MyProject.Core.Utility.Extensions.ToJson(Object value) in C:\Workspace\MyProject\MyProject.Service\Utility\Extensions.cs:line 15
at MyProject.Service.Service.TaskService.Save(Task task, ISession session) in C:\Users\jearl\Dropbox\Code\Workspace\MyProject\MyProject.Service\Service\TaskService.cs:line 34
at MyProject.Tests.Unit.Service.TaskServiceTests.Save_CallsWebService_WhenCalledWithTaskAndSession() in C:Workspace\MyProject\MyProject.Tests.Unit\Service\TaskServiceTests.cs:line 43 C:\Workspace\MyProject\MyProject.Service\Utility\Extensions.cs 15
问题是由我编写的扩展方法引起的,该方法是使用JSON.NET将POCO序列化为JSON。似乎JSON.NET依赖于System.Runtime.Serialization。
我已经尝试将JSON.NET和System.Runtime.Serialization引用添加到我的测试项目中,但这并没有解决问题。
我正在测试的程序集使用RestSharp,而RestSharp又依赖于JSON.NET。我尝试将System.Runtime.Serialization的引用直接添加到正在测试的程序集中,但也失败了。
有什么建议吗?
更新:我正在尝试按照以下评论中的建议跟踪文件,但Filemon已经停用。它的替换,Process Explorer,没有帮助,因为它似乎只显示devenv.exe进程当前保持打开的文件。搜索有问题的文件的引用只会产生两个不相关的引用。有没有办法看到我的测试运行的录音,所以我可以告诉它在哪里寻找.dll?
更新2:感谢您的建议。我通过使用Nuget将RestSharp和JSON.NET引用直接添加到单元测试项目来解决IO问题。现在我收到以下错误:
Error 5 Test 'MyProject.Tests.Unit.Service.TaskServiceTests.Save_CallsWebService_WhenCalledWithTaskAndSession' failed: System.InvalidProgramException : Common Language Runtime detected an invalid program.
at System.Xml.Linq.XDocument..ctor()
at RestSharp.Serializers.XmlSerializer.Serialize(Object obj)
at RestSharp.RestRequest.AddBody(Object obj, String xmlNamespace)
at RestSharp.RestRequest.AddBody(Object obj)
at MyProject.Service.Service.TaskService.Save(Task task, ISession session) in C:\MyProject\MyProject.Service\Service\TaskService.cs:line 34
at MyProject.Tests.Unit.Service.TaskServiceTests.Save_CallsWebService_WhenCalledWithTaskAndSession() in C:\MyProject\MyProject.Tests.Unit\Service\TaskServiceTests.cs:line 43 C:\MyProject\MyProject.Service\Service\TaskService.cs 34
在此网站上搜索主要返回对TFS开发的引用。大。
答案 0 :(得分:6)
为单元测试项目的WP7项目引用中的所有系统程序集设置“Copy Local”为true。我们在项目中使用Netwonsoft的Json和NUnit,没有任何问题。
干杯, 乔恩