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