【问题标题】:"System.MissingMemberException: The server factory could not be located" starting Microsoft.Owin self-hosted in TeamCity“System.MissingMemberException:找不到服务器工厂”启动 Microsoft.Owin 在 TeamCity 自托管
【发布时间】:2015-07-15 01:06:47
【问题描述】:

当 Teamcity 运行启动自托管 Web 应用程序的集成测试时,测试失败并出现以下错误:

System.MissingMemberException: The server factory could not be located for the given input: Microsoft.Owin.Host.HttpListener

抛出此错误的代码是:

var webApp = WebApp.Start<Startup>("http://*:52203/")

使用 Visual Studio(使用 Resharper 测试运行程序)执行测试时运行良好。 Teamcity 配置为使用JetBrains.BuildServer.NUnitLauncher.exe 可执行文件来运行测试。

我看到很多关于此错误的帖子都与 Microsoft.Owin.Host.HttpListener.dll 不存在于 bin\debug 或 bin\release 文件夹中。我可以确认此文件(以及随附的 .xml 文件)都存在于 TeamCity buildAgent 使用的 bin\release 文件夹中。没有 bin\debug 文件夹。

【问题讨论】:

  • 我遇到了同样的 Team City 错误,并且可以确认与正在测试的程序集旁边的 bin\release 文件夹中存在 dll 的情况相同。然而,我的在 Resharper 测试运行器中也一直失败。如果我了解更多,将发布答案。

标签: .net teamcity owin self-hosting


【解决方案1】:

我在我的 Powershell 脚本中遇到了这种情况,该脚本迭代我们所有的解决方案并使用 MSBuild 构建它们,然后在所有测试项目上调用 MSTest。此脚本用于在提交到 TFS 之前在本地构建和测试所有解决方案。在 VS 中运行测试时不会出现此问题。我相信这与this question有关。

在测试初始化​​中调用 WebApp.Start("http://*:52203/") 之前放置以下内容。

// This uber silly code is needed to ensure the Owin HttpListener assembly 
// is properly copied to the output directory by using it, utterly redonkulous.
var uberSillyNecessity = typeof(OwinHttpListener);
if (uberSillyNecessity != null) { }

【讨论】:

  • @SimonGreen 这个答案为我解决了这个问题 - 我遇到了同样的问题,测试在 VS 中运行良好,但在 Teamcity CI 测试中失败。在WebApp.Start 调用之前添加这些行效果很好 - 值得接受这一点,以便其他人可以找到它。
【解决方案2】:

我遇到了同样的问题: 在本地运行良好,但在 TeamCity 代理上运行失败。

我的测试项目通过 nuget 引用了 Microsoft.Owin.Host.HttpListener

对我有用的是在启动 Web 应用程序之前显式加载 Microsoft.Owin.Host.HttpListener dll。

// load assembly
AppDomain.CurrentDomain.Load(typeof(Microsoft.Owin.Host.HttpListener.OwinHttpListener).Assembly.GetName());

【讨论】:

  • 感谢您的建议,但遗憾的是添加该行没有任何区别。我直接在 WebApp.Start() 方法调用之前添加了它。它仍然在 WebApp.Start() 方法调用上抛出相同的异常,因此它愉快地调用了 Load() 方法而没有问题
  • 我可以确认我在测试项目和 webapi 项目中都安装了 Microsoft.Owin.Host.HttpListener nuget 包,版本 3.0.1
  • 我已经安装了 Microsoft.Owin.Host.HttpListener nuget 包,但错误仍然存​​在
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-07-04
  • 2016-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-25
相关资源
最近更新 更多