MsTest忽略app.config中的assemblyRedirect
我有一个项目,我最近将json nuget包升级到v10。 同一项目还引用了System.Net.Http.Formatting(通过Microsoft.AspNet.WebApi.Client.5.2.3包),它引用了json v6.0 dll 我在测试项目中有一个app.config,它具有:MsTest忽略app.config中的assemblyRedirect,redirect,app-config,.net-assembly,mstest,Redirect,App Config,.net Assembly,Mstest,我有一个项目,我最近将json nuget包升级到v10。 同一项目还引用了System.Net.Http.Formatting(通过Microsoft.AspNet.WebApi.Client.5.2.3包),它引用了json v6.0 dll 我在测试项目中有一个app.config,它具有: <dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
这是测试方法中失败的准确线路:
HttpRequestMessage.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());
我已经检查了我的整个解决方案,并确认没有任何项目引用json v6
当我使用MsTest时,是否有忽略重定向的原因?
(我也可以在测试项目的bin文件夹中看到带有重定向的testProjectName.dll.config)
此外,我还了解到使用testsettings文件可以解决此问题,但我不清楚在我的testsettings文件中需要什么才能重定向到较新的json。通过在testsettings中添加json 6 dll作为部署项,进一步了解了这一点。我现在看到的唯一问题是:只有少数测试失败。它们都失败了,错误是:error:System.MissingMethodException:Method not found:'Newtonsof t.Json.JsonSerializerSettings System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.get_SerializerSettings(),我假设System.Net.Http调用方法:get_SerializerSettings()这在json v10中已经不存在了。你知道吗?我有一个类似的问题。如果我没记错的话,我在所有使用System.Web.Http/AspNet.WebApiClient(依赖于json 6)重定向到json 10的项目中添加了app.config。(某些项目缺少app.config文件)
HttpRequestMessage.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());