watraplion
watraplion

Reputation: 287

SignalR - Type or namespace name 'Hub' could not be found

I am new to the SignalR library. I created a new web project in VS2010, then in Package Manager Console I executed the below command to set up the SignalR packages.

PM> Install-Package Microsoft.Aspnet.SignalR -pre

So it downloaded all the necessary files into the application.
----------
Successfully installed 'Microsoft.AspNet.SignalR 1.0.0-rc2'.
Successfully added 'jQuery 1.6.4' to demo.
Successfully added 'Microsoft.AspNet.SignalR.JS 1.0.0-rc2' to demo.
Successfully added 'Newtonsoft.Json 4.5.11' to demo.
Successfully added 'Microsoft.AspNet.SignalR.Core 1.0.0-rc2' to demo.
Successfully added 'Owin 1.0' to demo.
Successfully added 'Microsoft.AspNet.SignalR.Owin 1.0.0-rc2' to demo.
Successfully added 'Microsoft.Web.Infrastructure 1.0.0.0' to demo.
Successfully added 'Microsoft.Owin.Host.SystemWeb 1.0.0-rc2' to demo.
Successfully added 'Microsoft.AspNet.SignalR.SystemWeb 1.0.0-rc2' to demo.
Successfully added 'Microsoft.AspNet.SignalR 1.0.0-rc2' to demo.
----------

Now I added a new class file called LetsHub.cs.

In that file I wrote the following code,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR.Hubs;

namespace demo.Hubs
{
  [HubName("chatHub")]
  public class LetsChat : Hub
  {
      public void SendMsg(string Message)
      {
         Clients.All.addMessage(Message);
      }
  }
}

I am not able to inherit this Hub class.

Type or Namespace name Hub cound not be found ( are you missing using directive or assemblr reference ? ).

I am facing the same problem on VS 2012 as well.

Upvotes: 2

Views: 7375

Answers (3)

user3856437
user3856437

Reputation: 2377

The accepted answer doesn't work for me. In my .NET Core 3.1 this is my code:

using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;

namespace SignalRChat.Hubs
{
    public class ChatHub : Hub
    {
        public async Task SendMessage(string user, string message)
        {
            await Clients.All.SendAsync("ReceiveMessage", user, message).ConfigureAwait(false);
        }
    }
}

Upvotes: 2

user1598978
user1598978

Reputation: 13

Change public class LetsChat : Hub to

public class LetsChat : Microsoft.AspNet.SignalR.Hub

Upvotes: 1

pranav rastogi
pranav rastogi

Reputation: 4144

The Hub class was moved to a different namespace in in RC2. please change to Microsoft.AspNet.SignalR

Upvotes: 4

Related Questions