69

I have implemente signalR in window service.

private IDisposable SignalR { get; set; }

public void Configuration(IAppBuilder app)
{   
        var hubconfig=new Microsoft.AspNet.SignalR.HubConfiguration();
        hubconfig.EnableJSONP = true;

        app.UseCors(CorsOptions.AllowAll);
        app.MapSignalR(hubconfig);
}


private void StartSignalRServer(StringBuilder sbLog)
{
        try
        {
            this.SignalR = WebApp.Start(ServerURI); //This throws exception

            //this.SignalR= WebApp.Start<Startup>(ServerURI);
            sbLog.Append(string.Format("{0}--------SignalR Server Started------",Environment.NewLine));
        }
        catch (Exception ex)
        {
            sbLog.Append(string.Format("{0}Exception in StartSignalRServer=>{1}", Environment.NewLine,ex.Message));
        }
}

Exception:The server factory could not be located for the given input: Microsoft.Owin.Host.HttpListener

jignesh
  • 1,639
  • 1
  • 16
  • 18

5 Answers5

113

The Microsoft.Owin.Host.HttpListener assembly is a runtime reference in WebApp.Start. You need to include it in the project's references for it to be available for loading. Check the bin\Debug (etc) directory to make sure it's included. May as well add it as a nuget dependency as well.

Afzaal Ahmad Zeeshan
  • 15,669
  • 12
  • 55
  • 103
skoz
  • 1,268
  • 1
  • 9
  • 6
  • 7
    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:56
47

Install the package:

PM> Install-Package Microsoft.Owin.Host.HttpListener
Stephen
  • 1,737
  • 2
  • 26
  • 37
sedatiko
  • 609
  • 5
  • 5
  • 32
    Note that, for the copy-pasters, you shouldn't be using IncludePrerelease unless you WANT untested code in your app. – EKW Oct 08 '17 at 09:00
13

Install the Microsoft.Owin.Host.HttpListener package from Nuget using:

PM> Install-Package Microsoft.Owin.Host.HttpListener

(unlike an earlier answer you should avoid using -IncludePrerelease in production code)

Owen Pauling
  • 11,349
  • 20
  • 53
  • 64
1

Hello for same error message but in slithly different context that i have encountered:

Due to stupid referencing optimization which is totally immature regarding reflection. It happens that MsBuild do not copies the Microsoft.Owin.Host.HttpListener.dll in your startup project if it references another project which uses Owin.

In my case I have the error messsage mentioned above and opted for explicit reference in project using Owin by adding explicit use of the problematic dll so that msbuild sees a reference needed so Microsoft.Owin.Host.HttpListener.dll will be copied (not needed for other dll) -This issue come from the fact that owin stuff does reflection inside itself leaving msbuild completely dummy by removing this dll-:

using Microsoft.Owin.Host.HttpListener;
...
    _log.Debug("Loading type: "+ typeof(OwinHttpListener) + "..."); // Hack to force copy of Microsoft.Owin.Host.HttpListener.dll on target referencing project
Thierry Brémard
  • 625
  • 1
  • 5
  • 14
-1

I encountered same error.

In project A -- I am starting owin web service using WebApp.Start() in a function. In Project B -- I am calling project A's function here. Unfortunately Project B is not my .Net solution's startup project. Project C is my .Net Solution startup project.

If I Install nuget package using command Install-Package Microsoft.Owin.Host.HttpListener in solution's start up project i.e Project, C it works fine. If I do the same in Project B it does not work. So be careful while installing nuget package.