3

I need to connect to an ASP.NET SignalR hub from JavaScript. I am using the @aspnet/signalr npm package, with the following code to connect.

connection = new signalR.HubConnectionBuilder()
    .withUrl("<link to hub>", { accessTokenFactory: () => token })
    .build();
connection.start()

The same code works to connect to an ASP.NET Core SignalR hub, but for an ASP.NET SignalR hub, it returns the following error: TypeError: Cannot read property 'length' of undefined at "HttpConnection"

Is this an issue with incompatible versions? Can the @aspnet/signalr package be used to connect to an ASP.NET SignalR hub?

zane
  • 107
  • 1
  • 11

1 Answers1

2

Short answer, no you cannot use/mix the client/server packages. ASP.NET Core SignalR isn't compatible with clients or servers for ASP.NET SignalR.

See my older post/accepted answer here - https://stackoverflow.com/a/49153217/6263514

But for newer reference the docs here - https://learn.microsoft.com/en-us/aspnet/core/signalr/version-differences?view=aspnetcore-5.0

Frank M
  • 1,379
  • 9
  • 18
  • I understand that the npm package to be used here would be the older "signalr". Would it be recommended to use this package in React, as it uses jQuery, and React and jQuery are not generally used together? – zane Apr 28 '21 at 08:48
  • 1
    I can't recommend either way as I don't use React. I would recommend to search more on using it that way as there are references to using a "react native signalr" package such as - https://stackoverflow.com/questions/58796152/work-with-asp-net-signalr-in-react-native – Frank M Apr 28 '21 at 12:54