13

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.

Neil Fenwick
  • 5,906
  • 3
  • 29
  • 37
Simon Green
  • 1,031
  • 1
  • 9
  • 23
  • I have experienced the same Team City error, and can confirm the same as you regarding the presence of the dll's in the bin\release folder alongside the assembly being tested. However, mine also consistently fails inside the Resharper test runner too. Will post answer if I learn more. – Neil Fenwick May 15 '15 at 10:29

2 Answers2

16

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) { }
Community
  • 1
  • 1
Adam Caviness
  • 3,255
  • 30
  • 36
  • @SimonGreen this answer fixed it for me - I had the same issue, tests working fine in VS but failing in the Teamcity CI tests. Adding these lines prior to the `WebApp.Start` call worked perfectly - it would be worth accepting this so other people can find it. – Matt Hogan-Jones Feb 03 '16 at 14:49
13

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());
Kevin
  • 579
  • 5
  • 15
  • Thanks for the suggestion, but sadly adding that line made no difference. I added it directly before the WebApp.Start() method call. It still throws the same exception on the WebApp.Start() method call, so it has happily called the Load() method without problems – Simon Green May 15 '15 at 19:47
  • I can confirm that I have the Microsoft.Owin.Host.HttpListener nuget package, version 3.0.1, installed in both the Test project and the webapi project – Simon Green May 15 '15 at 20:00
  • I have installed Microsoft.Owin.Host.HttpListener nuget package and still the error persist – Waqas Jul 01 '15 at 11:08