【发布时间】:2015-10-20 15:20:07
【问题描述】:
我有一组由 MsTest 围绕 OWIN 执行的集成测试,使用 OWIN 启动方法进行自我主机。 测试非常简单,使用以下模式:
WebApp.Start<Startup>(url: appAddress);
HttpClient client = new HttpClient();
client.DefaultRequestHeaders
.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = client.GetAsync(uri).Result;
当我在本地 DEV 机器上运行测试时,它们是绿色的。 当我们在 Build Machine 中从 Visual Studio 运行测试时,它们是绿色的。 如果他们从队列中运行,几天前,我们开始从 OWIN 收到这个烦人的错误:
*** OWIN STARTED ***
{"Message":"An error has occurred.",
"ExceptionMessage":"Multiple types were found that match the controller named 'xxx'.
This can happen if the route that services this request ('odata/v1/{*odataPath}') found multiple controllers defined with the same name but differing namespaces, which is not supported.
The request for 'xxx' has found the following matching controllers:
namespace.V1.Controllers.xxxController
namespace.V1.Controllers.xxxController",
"ExceptionType":"System.InvalidOperationException","StackTrace":" at System.Web.Http.Dispatcher.DefaultHttpControllerSelector.SelectController(HttpRequestMessage request)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"}
这很奇怪,因为我们使用 Windsor 来解析控制器,并且我们还打印出 Windsor 中的注册信息,当然只有一个具有该名称的控制器。只有在 MsBuild 中执行代码时,我们才会在所有控制器上遇到这个问题……在 Build Machine 的 Visual Studio 中或在生产中,它可以工作。 可能是错误是其他东西,但被 OWIN 吞噬了?
【问题讨论】:
-
你用的是哪个版本的owin?
-
最新的应该是2.2 是一个奇怪的问题,因为配置在rebuild后已经自动整理出来了
-
我在 owin 3 和 nunit 上遇到了同样的问题,但它只发生在其中一个测试项目中。
-
在我的情况下,我们在 MsTest 中重新托管 OWIN 应用程序以避免出现问题,我可以在这里发布代码,稍等
标签: visual-studio mstest owin