简体   繁体   English

owin启动类visual studio 2012出错

[英]Error in owin startup class visual studio 2012

I am new to signal r and I am trying to create a basic chat application in c# visual studio 2012 but i am getting following error. 我是新来的信号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.

I have created 3 files: 我创建了3个文件:

1) first is Letschat.cs class as: 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) second file chat.aspx as 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 Named as Startup.cs 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();
        }

    }
}

I dont know where i am doing wrong any help in this regard will be appreciated. 我不知道我在哪里做错了任何这方面的帮助将不胜感激。

Was facing the same problem. 面临同样的问题。 Tried adding assembly level attribute, as suggested by @Praburaj 尝试添加程序集级别属性,如@Praburaj所示

You can try the following. 您可以尝试以下方法。

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();
        }

    }
}

I had the same problem but on Visual Studio 2013. 我在Visual Studio 2013上遇到了同样的问题。

Removing the \\bin and \\obj folders on my project then rebuilding it fixed the problem. 删除项目中的\\ bin\\ obj文件夹然后重建它修复了问题。

You just need to add OWIN StartUp class [ie StartUp1.cs] into your project. 您只需要将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();
        }
    }
}

If you have built your project, and then renamed it, this issue might occur. 如果您已构建项目,然后重命名它,则可能会出现此问题。 Try delete all the files in the bin folder and then run your project. 尝试删除bin文件夹中的所有文件,然后运行您的项目。 This worked for me. 这对我有用。

Just add this line 只需添加此行即可

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM