我正在使用AspNet Web Api客户端5.0,我试图单元测试一个web api控制器。错误单元测试webapi控制器
var encservice = new EncryptionService();
var acctservice = FakeServices.GetAccountService();
var controller = new AccountController(acctservice, encservice);
controller.Request = new HttpRequestMessage();
当代码
controller.Request.SetConfiguration(new HttpConfiguration());
执行我打一个异常
消息:无法加载文件或程序集“Newtonsoft.Json,版本= 4.5.0.0,文化=中立,PublicKeyToken = 30ad4fe6b2a6aeed'或其依赖项之一。定位的程序集清单定义与程序集引用不匹配。 (从HRESULT异常:0x80131040)
来源: System.Net.Http.Formatting
堆栈跟踪:在System.Net.Http.Formatting.JsonMediaTypeFormatter..ctor() 在System.Net .Http.Formatting.MediaTypeFormatterCollection.CreateDefaultFormatters() 在System.Net.Http.Formatting.MediaTypeFormatterCollection..ctor() 在System.Web.Http.HttpConfiguration.DefaultFormatters() 在System.Web.Http.HttpConfiguration .. ctor(HttpRouteCollection路由) 在System.Web.Http.HttpConfiguration..ctor() 在EMR.Test.Controller.AccountControllerTest.Should_Get(c)中:\ PremiumProjectsCollection \ EMR \ SRC \ EMRAzure \ EMRAzure \ EMR.Test \控制器\ AccountControllerTest.cs:线34
力新的版本。 JSON,我现在用的就是6.0
我也有一个程序集重定向在我confguration文件
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
,即时通讯使用的测试运行是MSTEST,VS2012
我面临同样的问题。你有没有解决它? –
@ Jean-FrançoisBeauchamp,我最终回滚到Newtonsoft.Json 4.5.0.0 – reggieboyYEAH
我遇到同样的问题。你有没有解决这个问题? –