CS0234名称空间“Microsoft”中不存在类型或命名空间名称“Owin”

时间:2016-03-25 23:56:32

标签: c# asp.net-mvc webserver

我正在使用VS 2015社区并尝试使用这些“简单”教程创建WebServer控制台:

OWIN and Katana part 1: the basics

ASP.NET Fundamentals

这两个教程看起来都很简单,但是当我尝试编译它时,我几乎陷入了同一个地方。这两个教程都引用了 DNX 4.5.1 (Microsoft.Owin.Host.HttpListener(3.0.1)和Microsoft.Owin.Hosting(3.0.1))& DNX Core 5.0 。这是第一个链接的代码(几乎与第二个链接相同(包括错误),因此我不会包含该代码):

using Microsoft.Owin.Hosting;
using Owin;
using System;

namespace KatanaBasics
{
  public class Program
    {
        public static void Main(string[] args)
        {
          string uri = "http://localhost:7990";

          using (WebApp.Start<startup>(uri))
          {
            Console.WriteLine("Web server on {0} starting.", uri);
            Console.ReadKey();
            Console.WriteLine("Web server on {0} stopping.", uri);
          }
        }
    }

    public class startup
  {
      public void Configuration(IAppBuilder appBuilder)
      {
        appBuilder.Run(owinContext =>
        {
          owinContext.Response.WriteAsync("Hello from OWIN web server");
        });
      }
  }
}

我从 owinContext =&gt; 开始获得红色波浪线,并一直持续到方法结束。 以下是我尝试编译时遇到的错误:

Severity    Code    Description Project File    Line    Suppression State
Error   CS0234  The type or namespace name 'Owin' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)  KatanaBasics.DNX Core 5.0

Severity    Code    Description Project File    Line    Suppression State
Error   CS0246  The type or namespace name 'Owin' could not be found (are you missing a using directive or an assembly reference?)  KatanaBasics.DNX Core 5.0

Severity    Code    Description Project File    Line    Suppression State
Error   CS0246  The type or namespace name 'IAppBuilder' could not be found (are you missing a using directive or an assembly reference?)   KatanaBasics.DNX Core 5.0

Severity    Code    Description Project File    Line    Suppression State
Error   CS0103  The name 'WebApp' does not exist in the current context KatanaBasics.DNX Core 5.0   

Severity    Code    Description Project File    Line    Suppression State
Error   CS1643  Not all code paths return a value in lambda expression of type 'Func<IOwinContext, Task>'   KatanaBasics.DNX 4.5.1

Owin不在DNX Core 5.0中,但它在DNX 4.5.1中。我想也许我可以移动或复制到DNX 4.5.1但似乎DNX Core 5.0是它想要默认的地方。

我找到了类似问题的解决方案,但我不明白所有的解释。例如,我读了一篇说改变目标的帖子,然而,我甚至找不到任何类似于他们描述的“修复”它的内容。那么,似乎我需要更早的DNX Core 5.0?如果是这样,我如何参考早期版本?非常感谢!

2 个答案:

答案 0 :(得分:2)

我遇到了同样的问题。为了笑容,我点击了ctrl-F5,当它问我是否想继续而不管错误时,我说“是”......它工作得很好。

我的工作机器出现了这些错误,我从2013年升级到VS2015 Update 3.

我在家中完成了相同的步骤,全新安装了VS2015 Update 3并没有得到这些(可能是错误的错误)。

这不是一个理想的答案,但我希望它有所帮助。

答案 1 :(得分:0)

在vs中,转到“工具”->“ Nuget软件包管理器”->“软件包管理器控制台” 并输入: 更新包

相关问题