Glauber A A
Glauber A A

Reputation: 181

MVC 6, SignalR on .Net461

I am trying to find a way to starts the signalR and Map the Hubs, in a MVC6 application that depends on .Net461 because of NHibernate.

I tried to use "Microsoft.AspNet.SignalR.Server":"3.0.0-beta5" but I keeping get a erro on package restore:

"The dependency Microsoft.AspNet.SignalR.Server 3.0.0-beta5 does not support framework .NetFramework, Version=v4.6.1."

{
  "dependencies": {
    "Domain": "1.0.0-*",
    "Globalization": "1.0.0-*",
    "Infra": "1.0.0-*",
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
    "Microsoft.AspNet.SignalR": "2.2.1",
    "Microsoft.AspNet.SignalR.Client": "2.2.1",
    "Microsoft.AspNet.SignalR.Core": "2.2.1",
    "Microsoft.AspNet.SignalR.JS": "2.2.1",
    "Microsoft.AspNet.SignalR.Owin": "1.2.2",
    "Microsoft.AspNet.SignalR.SystemWeb": "2.2.1",
    "Microsoft.AspNet.SignalR.Server":"3.0.0-beta5",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
    "Util": "1.0.0-*",
    "UtilTagHelpers": "1.0.0-*"
  },

    "tools": {
        "BundlerMinifier.Core": "2.0.238",
        "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
        "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
    },

    "commands": {
        "web": "Microsoft.AspNet.Server.Kestrel --server.urls http://*:5004"
    },
    "frameworks": {
        "net461": {
            "frameworkAssemblies": {
                "System.Runtime": {}
            }
        }
    },

    "buildOptions": {
        "emitEntryPoint": true,
        "preserveCompilationContext": true
    },

    "publishOptions": {
        "include": [
            "wwwroot",
            "Views",
            "Areas/**/Views",
            "appsettings.json",
            "web.config"
        ]
    },

    "scripts": {
        "prepublish": [ "bower install", "dotnet bundle" ],
        "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
    }
}

I tried the owin server too, but it don't starts too.

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

[assembly: OwinStartup(typeof(RLG.SignalR.OwinStart))]

namespace RLG.SignalR
{
    public class OwinStart
    {
        public void Configuration(IAppBuilder app)
        {
            app.MapSignalR();
        }
    }
}

What is the better way to use SignalR in this scenario ?

Upvotes: 2

Views: 1266

Answers (2)

J. Thompson
J. Thompson

Reputation: 521

In order to use SignalR with ASP.Net Core running on net461 framework you have to do a little setup.

1) You need to import the "dnxcore50" framework inside your "net461" configuration.

"frameworks": {
    "net461": {
      "imports": "dnxcore50"
    }
  },

2) You need to create a new file NuGet.config in the root directory of the Web Application project. Once replace the content with the following:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="AspNetCore" value="https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json" />
    <add key="NuGet" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration>

3) Add the appropriate dependencies to your project.json file.

"Microsoft.AspNetCore.SignalR.Server": "0.2.0-*"
"Microsoft.AspNetCore.WebSockets": "0.2.0-*"

4) Add the appropriate dependencies to your bowser.json file.

"signalr": "^2.2.1"

5) Add the Hubs folder to the root of your Web Application project.

6) In your Startup.cs file add the following line in the Configure(app, env, loggerFactory) method.

app.UseSignalR();

7) In your Startup.cs file add the following line in the ConfigureServices(services) method.

services.AddSignalR(options => options.Hubs.EnableDetailedErrors = true);

At this point setting up your hubs in both C# and JavaScript is identical to older versions or SignalR. I have this successfully working running on the .Net Frameworks targeting 4.6.1.

Partial credit given to: https://chsakell.com/2016/10/10/real-time-applications-using-asp-net-core-signalr-angular/

Upvotes: 2

Daniel Kravetz Malabud
Daniel Kravetz Malabud

Reputation: 783

Use the latest stable (read: non-beta) version, it should work just fine

EDIT: It seems to be version 2.2.1

Upvotes: 0

Related Questions