简体   繁体   中英

OwinStartup and startup in signalr in asp.net mvc

i have a problem with SignalR in asp.net mvc i add a package below: 在此输入图像描述

and add Startup.cs

using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(Paksh.Startup))]
namespace Paksh
 {
   public class Startup
    {
      public static void ConfigureSignalR(IAppBuilder app)
       {
                  app.MapSignalR();
       }
     }
 }

but i get error:

The following errors occurred while attempting to load the app. - The OwinStartupAttribute.FriendlyName value '' does not match the given value 'ProductionConfiguration' in Assembly 'Paksh, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. - The given type or method 'ProductionConfiguration' was not found. Try specifying the Assembly. 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.

The error clearly states that

The given [...] method 'ProductionConfiguration' was not found.

This means that the OWIN Startup Class Detection was looking for a method called ProductionConfiguration on the type you provided ( Paksh.Startup ), but could not find it. Something tells me that you have something similar to this in your web.config as well:

<appSettings>  
  <add key="owin:appStartup" value="ProductionConfiguration" />       
</appSettings>

You have several options to solve this:

  1. Change the name of the ConfigureSignalR method to ProductionConfiguration
  2. Specify the correct method name in the OwinStartupAttribute : [assembly: OwinStartup(typeof(Paksh.Startup), "ConfigureSignalR")]

To get to know the OWIN startup class detection, read more here .

I had a similar error to OP, but using attributes instead of web.config . I had:

[assembly: OwinStartup("Configuration", typeof(StartUp))]
namespace WebPipes
{
    public class StartUp
    {
        public void Configuration(IAppBuilder app)
        {
            GlobalConfiguration.Configuration.UseSqlServerStorage("HangfireDB");

            app.UseHangfireServer();
            app.UseHangfireDashboard();
        }
    }
}

The parameters in OwinStartup were incorrect, the first parameter denotes the friendly name , not the method name. The following code does work, though:

[assembly: OwinStartup(typeof(StartUp), "Configuration")]
namespace WebPipes
{
    public class StartUp
    {
        public void Configuration(IAppBuilder app)
        {
            GlobalConfiguration.Configuration.UseSqlServerStorage("HangfireDB");

            app.UseHangfireServer();
            app.UseHangfireDashboard();
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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