Answered by:
ASP.NET 5 - app.UseSignalR - error

Question
-
User-953595010 posted
Hello,
I'm trying out SignalR based on the book "SignalR Programming in Microsoft ASP.NET". I'm running ASP.NET 5 with 1.0.0.-rc1-update1. I already there are some changes: eg I suppose app.MapSignalR is replaced by UseSignalR?
This is my project.json
{ "version": "1.0.0-*", "compilationOptions": { "emitEntryPoint": true }, "dependencies": { "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final", "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final", "Microsoft.AspNet.SignalR.Server": "3.0.0-rc1-final" }, "commands": { "web": "Microsoft.AspNet.Server.Kestrel" }, "frameworks": { "dnx451": { }, "dnxcore50": { } }, "exclude": [ "wwwroot", "node_modules" ], "publishExclude": [ "**.user", "**.vspscc" ] }
I have the following code in Startup.cs
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.AspNet.SignalR; namespace SignalRTest { public class Startup { // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app) { app.UseIISPlatformHandler(); app.UseSignalR<EchoConnection>("/echo"); app.Run(async (context) => { await context.Response.WriteAsync("Hello World!"); }); } // Entry point for the application. public static void Main(string[] args) => WebApplication.Run<Startup>(args); } }
everything builds fine but when running my project I get:
An exception of type 'System.InvalidOperationException' occurred in Microsoft.AspNet.Http.Abstractions.dll but was not handled in user code
Additional information: Unable to resolve service for type 'Microsoft.Extensions.OptionsModel.IOptions`1
"app.UseSignalR<EchoConnection>("/echo"); is the cause of this runtime error."
Anyone can help me to resolve this?
Thanks.
GuySunday, December 13, 2015 12:14 AM
Answers
-
User61956409 posted
Hi gdillen,
Firstly, please try to use the following code to add SignalR to the pipeline.
app.UseSignalR();
Besides, please refer to the following links that explained how to use SignalR in ASP.NET 5.
http://dotnetthoughts.net/using-signalr-in-asp-net-5/
https://code.msdn.microsoft.com/The-ASPNET-vNext-Real-Time-b1d27fe4
Best Regards,
Fei Han
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, December 14, 2015 7:24 AM -
User-2046572174 posted
looks like the dependency injection is complaining because you didnt setup the services for signalr. try adding: services.AddSignalr(); to your configureservices method.- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, December 22, 2015 12:05 PM
All replies
-
User61956409 posted
Hi gdillen,
Firstly, please try to use the following code to add SignalR to the pipeline.
app.UseSignalR();
Besides, please refer to the following links that explained how to use SignalR in ASP.NET 5.
http://dotnetthoughts.net/using-signalr-in-asp-net-5/
https://code.msdn.microsoft.com/The-ASPNET-vNext-Real-Time-b1d27fe4
Best Regards,
Fei Han
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, December 14, 2015 7:24 AM -
User-2046572174 posted
looks like the dependency injection is complaining because you didnt setup the services for signalr. try adding: services.AddSignalr(); to your configureservices method.- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, December 22, 2015 12:05 PM