6
votes

I am having difficult time to use SignalR in vNext project (epmty template).

Firsty I added SignalR.Server dependency to my project.json file and it looks now like this:

{
    "webroot": ".",
    "dependencies": {
        "Microsoft.AspNet.Server.IIS": "1.0.0-beta3",
        "Microsoft.AspNet.Server.WebListener": "1.0.0-*",
        "Microsoft.AspNet.StaticFiles": "1.0.0-*",
        "Microsoft.AspNet.SignalR.Server": "3.0.0-*",
        "Serilog": "1.4.113.0"
},
    "commands": {
        "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5002"
    },
    "frameworks": {
        "dnx451": {
            "dependencies": {
                "Microsoft.Framework.Logging.Serilog": "1.0.0-*"
            }
        },
        "dnxcore50": { }
    }
}

And then I wanted to map the SignalR in my Startup.cs (as i found somwhere on git)

 public void ConfigureServices(IServiceCollection services)
    {
        services.AddSignalR(options =>
        {
            options.Hubs.EnableDetailedErrors = true;
        });
    }

    public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
    {
#if DNX451
        string OutputTemplate = "{SourceContext} {Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}";

        var serilog = new LoggerConfiguration()
            .MinimumLevel.Verbose()
            .WriteTo.RollingFile(@".\SignalR-Log-{Date}.txt", outputTemplate: OutputTemplate);

        loggerFactory.AddSerilog(serilog);
#endif

        app.UseFileServer();

        app.UseSignalR<RawConnection>("/raw-connection");
        app.UseSignalR();
    }

, but when i add at the top:

using Microsoft.AspNet.SignalR;

I get error:

The type or namespace name 'SignalR' does not exist in the namespace >'Microsoft.AspNet' (are you missing an assembly reference?) VersaWeb.ASP.NET >5.0 c:\Users\Jakub\documents\visual studio >2015\Projects\VersaWeb\src\VersaWeb\Startup.cs

And I am stuck right now.


EDIT:

The problem had to be with project.json becouse when i copied the one from music store the problem vanished.

Here is my current project.json (probably some of dependencies are not needed so i am gonna further test it)

{
"authors": [
    "author"
],
"description": "your description here",
"version": "1.0.0",
"compilationOptions": { "warningsAsErrors": true, "define": [ "DEMO", "TESTING" ] },
"code": [
    "**/*.cs"
],
"bundleExclude": "*.cmd",
"webroot": "wwwroot",
"dependencies": {
    "EntityFramework.SqlServer": "7.0.0-beta3",
    "EntityFramework.InMemory": "7.0.0-beta3", // For Mono.
    "Kestrel": "1.0.0-beta3",
    "Microsoft.AspNet.Diagnostics": "1.0.0-beta3",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta3",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta3",
    "Microsoft.AspNet.Mvc": "6.0.0-beta3",
    "Microsoft.AspNet.Security.OpenIdConnect": "1.0.0-beta3",
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta3",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-beta3",
    "Microsoft.AspNet.SignalR.Server": "3.0.0-beta3",
    "Microsoft.AspNet.StaticFiles": "1.0.0-beta3",
    "Microsoft.Framework.Cache.Memory": "1.0.0-beta3",
    "Microsoft.Framework.CodeGenerators.Mvc": "1.0.0-beta3",
    "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta3",
    "Microsoft.Framework.Logging.Console": "1.0.0-beta3"
},
"commands": {
    "gen": "Microsoft.Framework.CodeGeneration",
    "kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004",
    "run": "run server.urls=http://localhost:5003",
    "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5002"
},
"frameworks": {
    "aspnet50": { },
    "aspnetcore50": { }
}
}
2
Maybe the error applies only to dnxcore? Try to comment out ""dnxcore50": { }" in project.json to verify that. Also, checkout MusicStore sample, which uses SignalR. I am also using SignalR in my vnext project (although with kre, not the new dnx stuff), so it is definitely doable.qbik
I commented dnxcore50 and nothing happened but now i have downloaded musicstore and I will check and compare my files with storesJakub Wisniewski
MusicStore sample works - and acording to web console web sockets were correctly opened - i will now inspect codeJakub Wisniewski
@qbik - you can now write reply and i will mark as answere - music store sample helped me a lot :) ThanksJakub Wisniewski
Great! Could you write, what was wrong in your project and what helped?qbik

2 Answers

4
votes

Checkout MusicStore sample, which uses SignalR. I am also using SignalR in my vnext project (although with kre, not the new dnx stuff), so it is definitely doable.

2
votes

Looking at your initial project.json it was probably the fact you were attempting to target dnx451 but running against the wrong .NET development runtime.

The main thing I found when working with this vNext stuff is that all of your references need to be on the same level beta3/beta4/beta5 and your .NET runtime must match (frameworks in project.json). I believe beta3 used aspnet50 and since the beta4 rename it is now dnx451.

It is worth running dnvm list on the command line and seeing what is installed and what is set to the 'default' alias as this is what Visual Studio will use when running your application (unless overriden in the solution global.json file).