'Owin.IAppBuilder' does not contain a defi

2019-01-18 09:27发布

问题:

Error

'Owin.IAppBuilder' does not contain a definition for 'MapSignalR' and no extension method 'MapSignalR' accepting a first argument of type 'Owin.IAppBuilder' could be found (are you missing a using directive or an assembly reference?)

Code

using Microsoft.Owin;
using Owin;

[assembly: OwinStartup(typeof(SignalRChat.Startup))]
namespace SignalRChat
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            // Any connection or hub wire up and configuration should go here
            app.MapSignalR();
        }
    }
}  

Any help would be greatly appreciated...

Update

signalR version 2.0.3
Microsoft Owin version 2.0.2
Owin version 1.0.0
Visual Studio 2012

回答1:

Only install this nuget:

Install-Package Microsoft.AspNet.WebApi.OwinSelfHost



回答2:

Finally was able to solve it by adding signalR dependencies before adding signalR from NuGet Packages
Step's I followed:

  1. Added Microsoft.Owin //version 2.0.1
  2. Added Microsoft.Owin.Security //version 2.0.1
  3. Added Microsoft Asp.Net SignalR

The reason I discovered was a problem with version 2.0.2 of Microsoft.Owin and Microsoft.Owin.Security and then adding a class named Startup.cs with following code:

using Microsoft.Owin;
using Owin;

[assembly: OwinStartup(typeof(webApp.Startup))]
namespace webApp
{
    public static class Startup
    {
        public static void Configuration(IAppBuilder app)
        {
            app.MapSignalR();
        }
    }
}  

Directly adding Microsoft Asp.Net SignalR from NuGet adds version 2.0.2 of Microsoft.Owin and Microsoft.Owin.Security which creates the problem.
Hope it helps someone...!!



回答3:

Update-Package Owin -Reinstall

worked for me



回答4:

Using MVC5, enter your Startup.cs file.

Add IAppBuilder appBuilder to Configure():

 public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IAppBuilder appBuilder)
    {

Then, under

app.UseMvc(routes =>
{
    routes.MapRoute(
        name: "default",
        template: "{controller=Home}/{action=Index}/{id?}");
});

add appBuilder.MapSignalR();



回答5:

Asp.Net 5 empty mvc project out of the box creates something that looks like this

 using Microsoft.Owin;
using Owin;
namespace DeadlyChat
{
public class Startup
{
    // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
    public void ConfigureServices(IServiceCollection services)
    {
    }

    public void Configure(IApplicationBuilder app)
    {
        app.MapSignalR();



       }
    }
}

Took me a while to notice that Configure was supposed to be Configuration and IApplicationBuilder needs to be IAppBuilder. I also pulled off the assembly annotation above the namespace.

I wound up scrapping trying to use Asp.Net 5 couldn't get it to work. Went back to 4.6 and everything worked fine. Followed this walkthrough http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr



回答6:

I had this same problem. Turns out my .csproj file the first line:

Project ToolsVersion="12.0" didn't match my other files. Changed it to:

Project ToolsVersion="14.0"

and no more compile issue.