没有找到OWIN HttpListener

本文关键字:OWIN HttpListener | 更新日期: 2023-09-27 18:15:57

当我尝试开始:

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

得到以下异常。根本原因是什么?

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)

没有找到OWIN HttpListener

您必须在您的项目参考中包含Microsoft.Owin.Host.HttpListener.dll

可以通过NuGet添加。

但是,如果代码执行:
WebApp.Start<SrvcHst> (...);

包含在类库中,确保使用该库的可执行文件也包含对Microsoft.Owin.Host.HttpListener.dll的引用,否则它将不会被部署到您的程序中,因为没有从类库中显式引用它。

查看bin/Debug文件夹,确保DLL在那里

确保您有Microsoft.Owin.Host.HttpListener安装包

安装包,使用命令行:

Install-Package Microsoft.Owin.Host.HttpListener

有时NuGet引用是在不完整状态下添加的。如果您已经安装了这些包,但是没有包含引用,请尝试通过;

重新安装它们。
Update-Package -reinstall

对Pierre和Damith的回答的小小补充。如果您使用的是Mac OS,请运行以下命令安装HttpListener:

dnu install Microsoft.Owin.Host.HttpListener