c# - 找不到 OWIN HttpListener

标签 c# exception .net-4.5 owin asp.net-web-api2

当我尝试开始时:

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)

最佳答案

您必须在项目引用中包含 Microsoft.Owin.Host.HttpListener.dll

您可以通过 NuGet 添加它。

但是,如果代码执行:

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

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

查看您的 bin/Debug 文件夹并确保 DLL 在那里。

关于c# - 找不到 OWIN HttpListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25090211/

相关文章:

c# - 如何使用 C# 检查文本框是否包含来自 TXT 文件的行

c++ - 使用 RAII 嵌套异常

visual-studio - 未知的构建错误, 'Exception of type ' System.OutOfMemoryException' 被抛出

c# - 访问同一个类中的公共(public)方法需要一个实例?

c# - 在 select 语句中重用匿名变量

Java:发送附件电子邮件时出现异常

.net - 使用 NSIS 检查 .NET4.5+

c# - INSERT INTO 有没有更省事的方法?

c# - 如何在 Linq 提取方法中使用 order by 和 group by?

c# - WPF TreeView 中的 "Link"项