Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 835
Simon Green Avatar asked May 05 '15 10:05

Simon Green


2 Answers

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) { }
like image 110
Adam Caviness Avatar answered Nov 08 '22 07:11

Adam Caviness


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());
like image 13
Kevin Avatar answered Nov 08 '22 08:11

Kevin