72

When I try to start :

WebApp.Start<SrvcHst>(new StartOptions { Port = 9956, 
     ServerFactory = "Microsoft.Owin.Host.HttpListener" });

I get the following exception. What could be the root cause?

System.MissingMemberException was caught
  HResult=-2146233070
  Message=The server factory could not be located for the given input: Microsoft.Owin.Host.HttpListener
  Source=Microsoft.Owin.Hosting
  StackTrace:
       at Microsoft.Owin.Hosting.Engine.HostingEngine.ResolveServerFactory(StartContext context)
       at Microsoft.Owin.Hosting.Engine.HostingEngine.Start(StartContext context)
       at Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start(StartOptions options)
       at Microsoft.Owin.Hosting.Starter.HostingStarter.Start(StartOptions options)
       at Microsoft.Owin.Hosting.WebApp.StartImplementation(IServiceProvider services, StartOptions options)
       at Microsoft.Owin.Hosting.WebApp.Start(StartOptions options)
       at Microsoft.Owin.Hosting.WebApp.Start[TStartup](StartOptions options)
leppie
  • 115,091
  • 17
  • 196
  • 297
GilliVilla
  • 4,998
  • 11
  • 55
  • 96

4 Answers4

131

You have to include Microsoft.Owin.Host.HttpListener.dll in your project references.

You can add it through NuGet.

However, if the code executing:

WebApp.Start<SrvcHst> (...);

is contained within a class library, make sure that the executable consuming the library also includes the reference to Microsoft.Owin.Host.HttpListener.dll, or else it would not get deployed with your program, as there are no explicit references to it from the class library.

Have a look at your bin/Debug folder and make sure the DLL is there.

Pierre Arnaud
  • 10,212
  • 11
  • 77
  • 108
  • 3
    Thanks Pierre. A suggestion for improvement to your answer: I do not want to have to manually add that reference to all applications that will use my library. Instead I simply reference something (anything) inside the HttpListener assembly from my own assembly, so that the build is forced to bring along that DLL to the application's output folder. – Bent Tranberg Dec 01 '15 at 11:06
  • Good point; indeed, you just have to make sure the `Microsoft.Owin.Host.HttpListener.dll` gets included. However that's done is up to you :-) – Pierre Arnaud Dec 02 '15 at 12:09
  • 8
    why is this not a dependency of Microsoft.Owin.Hosting ? – Josh Sutterfield Jul 25 '16 at 20:35
  • You need to set bold **make sure that the executable consuming the library also includes the reference** – qakmak Feb 22 '20 at 10:41
47

Make sure you have install package Microsoft.Owin.Host.HttpListener

To install package, use this command line :

Install-Package Microsoft.Owin.Host.HttpListener
Johann67
  • 385
  • 6
  • 16
Damith Asanka
  • 934
  • 10
  • 12
  • I had a reference to this dll but for some reason it was not copied to the bin-Directory. I then tried your Suggestion to Install it via Nuget and it worked. Now it's copied to the Output-directory – Tobias Koller Oct 03 '15 at 10:13
  • You need to add reference to the HttpListener in the "StartUp Project". So, be carefull if you use `WebApp.Start` in another project. – Johann67 Dec 03 '18 at 13:55
7

Sometimes NuGet references are added in an incomplete state. If you have the packages installed, however references are not included, try reinstalling them via;

Update-Package -reinstall

in the package manager console.

Daniel Park
  • 3,903
  • 4
  • 23
  • 38
  • I also tried to use Update-Package -reinstall but in the middle of the process there was an error and all packages havee been deleted. I manually had to add all references again...so be careful ;) – Tobias Koller Oct 03 '15 at 10:09
  • Simply restore packages.config from source control, or make sure you backup beforehand – Daniel Park Apr 02 '17 at 22:50
0

Small addition to Pierre's and Damith's answer. If you are using Mac OS, run the following command to install HttpListener:

dnu install Microsoft.Owin.Host.HttpListener
Baidaly
  • 1,829
  • 1
  • 15
  • 16