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

3

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.

Boehmer answered 5/5, 2015 at 10:33 Comment(1)
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.Rajasthani
D
17

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) { }
Distill answered 1/10, 2015 at 16:59 Comment(1)
@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.Battiste
F
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());
Fudge answered 15/5, 2015 at 15:39 Comment(3)
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 problemsBoehmer
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 projectBoehmer
I have installed Microsoft.Owin.Host.HttpListener nuget package and still the error persistCutthroat
M
0

I found a solution for this issue, I hope it helps:

var url = "https://example.com";
var options = new StartOptions(url);
options.ServerFactory = typeof(OwinServerFactory).AssemblyQualifiedName;
myHost = WebApp.Start<Startup>(options);

It works without copying the Microsoft.Owin.Host.HttpListener.dll to the bin directory.

Milliner answered 6/12, 2022 at 12:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.