owin启动类visual studio 2012出错

时间:2013-11-28 10:57:51

标签: c# signalr owin

我是信号r的新手,我正在尝试在c#visual studio 2012中创建一个基本的聊天应用程序,但我收到了以下错误。

The following errors occurred while attempting to load the app.
- No assembly found containing an OwinStartupAttribute.
- The discovered startup type 'SignalRTutorials.Startup, SignalRTutorials, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' 
    conflicts with the type 'Microsoft.VisualStudio.Web.PageInspector.Runtime.Startup, Microsoft.VisualStudio.Web.PageInspector.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 
 Remove or rename one of the types, or reference the desired type directly. 
 To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config. 
 To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.

我创建了3个文件:

1)首先是Letschat.cs类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
namespace SignalRTutorials
{
    [HubName("myChatHub")]
    public class LetsChat:Hub
    {
        public void send(string message)
        {

            Clients.All.addMessage(message);

        }
    }
}

2)第二个文件chat.aspx为

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Chat.aspx.cs" Inherits="SignalRTutorials.Chat" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.6.4.min.js"></script>
    <script src="Scripts/jquery-1.6.4-vsdoc.js"></script>
    <script src="Scripts/jquery-1.6.4.min.js"></script>
    <script src="Scripts/jquery.signalR-2.0.0.js"></script>
    <script src="Scripts/jquery.signalR-2.0.0.min.js"></script> 
</head>
<body>
    <form id="form1" runat="server">
         <script type="text/javascript">

             $(function()
             {
                 var IWannaChat=$.connection.myChatHub;
                 IWannaChat.client.addMessage=function(message){

                     $('#listMessages').append('<li>'+message+'</li>');
                 };
                 $("#SendMessage").click(function(){
                     IWannaChat.server.send($('#txtMessage').val());
                 });
                 $.connection.hub.start();
             });


         </script>
    <div>
    <input type="text" id="txtMessage" />
         <input type="text" id="SendMessage" value="broadcast" />
        <ul id="listMessages">



        </ul>
    </div>
    </form>
</body>
</html>

3)class命名为Startup.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Web;
using System.Web.Routing;
using Microsoft.AspNet.SignalR;
using Microsoft.Owin.Security;
using Owin;


namespace SignalRTutorials
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.MapSignalR();
        }

    }
}

我不知道我在哪里做错了任何有关这方面的帮助都将不胜感激。

5 个答案:

答案 0 :(得分:14)

面临同样的问题。 尝试添加程序集级别属性,如@Praburaj

所示

您可以尝试以下操作。

using Microsoft.AspNet.SignalR;
using Microsoft.Owin.Security;
using Owin;

//add the attribute here
[assembly: OwinStartup(typeof(SignalRTutorials.Startup))]

namespace SignalRTutorials
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.MapSignalR();
        }

    }
}

答案 1 :(得分:6)

我在Visual Studio 2013上遇到了同样的问题。

删除项目中的 \ bin \ _ obj 文件夹,然后重建它修复了问题。< / p>

答案 2 :(得分:2)

你只需要添加OWIN StartUp类[即StartUp1.cs]进入你的项目。

using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;

[assembly: OwinStartup(typeof(UserInterfaceLayer.Hubs.Startup))]

namespace UserInterfaceLayer.Hubs
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.MapSignalR();
        }
    }
}

答案 3 :(得分:0)

如果您已构建项目,然后重命名它,则可能会出现此问题。尝试删除bin文件夹中的所有文件,然后运行您的项目。这对我有用。

答案 4 :(得分:0)

只需添加此行

即可
[assembly: OwinStartup(typeof(SignalRTutorials.Hubs.Startup))] as described here

http://yazilimsozluk.com/no-assembly-found-containing-an-owinstartupattribute