“System.MissingMemberException:无法找到服务器工厂”启动TeamCity中自托管的Microsoft.Owin

时间:2015-05-05 10:33:45

标签: .net teamcity owin self-hosting

当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可执行文件来运行测试。

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

2 个答案:

答案 0 :(得分:14)

我在我的Powershell脚本中遇到了这个问题,它迭代我们所有的解决方案并使用MSBuild构建它们,然后在所有测试项目上调用MSTest。这个脚本用于构建&amp;在提交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) { }

答案 1 :(得分:10)

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

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

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

aploetz@cqlsh:stackoverflow2> SELECT customerid, datebucket, sensorid, dateof(datatime), datatime, sensordata1, sensordata2
FROM sensordata2 WHERE customerid=3221b1d7-13b4-40d4-b41c-8d885c63494f 
AND datebucket='20150515' LIMIT 10;

 customerid                           | datebucket | sensorid | dateof(datatime)         | datatime                             | sensordata1 | sensordata2
--------------------------------------+------------+----------+--------------------------+--------------------------------------+-------------+-------------
 3221b1d7-13b4-40d4-b41c-8d885c63494f |   20150515 |       A1 | 2015-05-15 10:34:34-0500 | e3a15c20-fb17-11e4-93da-21b264d4c94d |          47 |          24
 3221b1d7-13b4-40d4-b41c-8d885c63494f |   20150515 |       A1 | 2015-05-15 10:34:34-0500 | e39ffc90-fb17-11e4-93da-21b264d4c94d |          46 |          23
 3221b1d7-13b4-40d4-b41c-8d885c63494f |   20150515 |       A1 | 2015-05-15 10:34:34-0500 | e39e4ee0-fb17-11e4-93da-21b264d4c94d |          45 |          22
 3221b1d7-13b4-40d4-b41c-8d885c63494f |   20150515 |       B1 | 2015-05-15 10:34:22-0500 | dc64a340-fb17-11e4-93da-21b264d4c94d |          47 |          24
 3221b1d7-13b4-40d4-b41c-8d885c63494f |   20150515 |       B1 | 2015-05-15 10:34:22-0500 | dc60aba0-fb17-11e4-93da-21b264d4c94d |          46 |          23
 3221b1d7-13b4-40d4-b41c-8d885c63494f |   20150515 |       B1 | 2015-05-15 10:34:22-0500 | dc5d0220-fb17-11e4-93da-21b264d4c94d |          45 |          22
 3221b1d7-13b4-40d4-b41c-8d885c63494f |   20150515 |       A1 | 2015-05-15 10:32:16-0500 | 90e27fa0-fb17-11e4-93da-21b264d4c94d |          47 |          24
 3221b1d7-13b4-40d4-b41c-8d885c63494f |   20150515 |       A1 | 2015-05-15 10:32:16-0500 | 90e0aae0-fb17-11e4-93da-21b264d4c94d |          46 |          23
 3221b1d7-13b4-40d4-b41c-8d885c63494f |   20150515 |       A1 | 2015-05-15 10:32:16-0500 | 90de8800-fb17-11e4-93da-21b264d4c94d |          45 |          22
 3221b1d7-13b4-40d4-b41c-8d885c63494f |   20150515 |       A1 | 2015-05-15 10:25:24-0500 | 9b5d1ae0-fb16-11e4-93da-21b264d4c94d |          47 |          24

(10 rows)