“System.MissingMemberException: The server factory could not be located” starting Microsoft.Owin self-hosted in TeamCity

天涯浪子 提交于 2019-12-12 08:21:47

问题


When Teamcity runs an integration test that starts a self-hosted webapplication, the test fails with the error:

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

The code throwing this error is:

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

The test runs fine when executed withing Visual Studio (using the Resharper test runner). Teamcity is configured to use the JetBrains.BuildServer.NUnitLauncher.exe executable to run the test.

I see a lot of posts regarding this error are to do with the because the Microsoft.Owin.Host.HttpListener.dll is not present in the bin\debug or bin\release folder. I can confirm that this file (and the accompanying .xml file) are both present in the bin\release folder used by the TeamCity buildAgent. There is no bin\debug folder present.


回答1:


I encountered this in my Powershell script that iterates all of our solutions and builds them with MSBuild and then invokes MSTest on all Test projects. This script is used to build & test all solutions locally before committing to TFS. This issue does not arise while running the tests within VS. I believe this to be related to this question.

Place the following just before calling WebApp.Start("http://*:52203/") in the test initialization.

// 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) { }



回答2:


I was having same issue: Runs fine locally, but fails on TeamCity agent.

My test project had a reference, through nuget, to Microsoft.Owin.Host.HttpListener

What worked for me was explicitly loading the Microsoft.Owin.Host.HttpListener dll before starting the web app.

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


来源:https://stackoverflow.com/questions/30050588/system-missingmemberexception-the-server-factory-could-not-be-located-startin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!