Prateek Saini
Prateek Saini

Reputation: 23

'Hub' is an ambiguous reference

I'm using these libraries in my application:

using SignalRDemo.Hubs;
using Microsoft.AspNet.SignalR.Hubs;
using System.Threading.Tasks;
using System.Web.Script.Serialization;

Now I have to implement IConnect, IDisconnect interface. So, I added using SignalR.Hubs; and added a function in my ChatHub class:

   public class ChatHub : Hub, IConnected, IDisconnect
     {
     public Task Connect()
            {
                //Call the joined method on all connected clients
                return Clients.joined(Context.ConnectionId);

            }
     }

Client Side Code:

chatHub.joined = function (connectionId) {
                $('#connections').append('<li>Connect: ' + connectionId + '</li>');
            }

But, when I build the solution it shows an error.

   'Hub' is an ambiguous reference between 'Microsoft.AspNet.SignalR.Hub' and 'SignalR.Hubs.Hub' 

Upvotes: 1

Views: 255

Answers (2)

emre nevayeshirazi
emre nevayeshirazi

Reputation: 19241

You probably have two different assemblies of SignalR in your project. Latest version uses Microsoft.AspNet.SignalR namespace. Check your assemblies and remove the previous version.

Otherwise you need to tell the compiler which namespace you want to use.

public class ChatHub : Microsoft.AspNet.SignalR.Hub

Edit:

halter74 pointed out that IConnected and IDisconnect interfaces have been removed. OnConnected, OnDisconnected and OnReconnected virtual methods can be found on Hub Class.

Upvotes: 1

Tommi
Tommi

Reputation: 3247

This means what it say. Hub class defined in Microsoft.AspNet.SignalR and SignalR.Hubs.Hub namespaces and you using both in your code, so compiler don't know which one to use; You must explicitly define proper class:

public class ChatHub : SignalR.Hubs.Hub, IConnected, IDisconnect

or

using Hub = SignalR.Hubs.Hub;

Upvotes: 0

Related Questions