Search code examples
c#asp.netvb.netsignalr

Setting and Getting SignalR Caller properties in vb.net


In the SignalR Chat sample, Caller properties are set using the code;

Caller.name = newUser.Name;

Then later on, this property is read;

string name = Caller.name;

I have my own SignalR project, but this one is vb.net, and when i do the same setting and getting of the Caller properties, it doesn't work

Public Sub SetCaller()
    Caller.name = "tim"
End Sub

Public Sub GetCaller()
    Dim name as string = Caller.name
End Sub

GetCaller() throws an error of "Conversion from type 'Task(Of Object)' to type 'String' is not valid."

The exact same code, but in c# works fine;

public void SetCaller(){
    Caller.name = "tim";
}

public void GetCaller(){
    string name = Caller.name;
}

Is my code wrong in vb.net?


Solution

  • No, you're not doing anything wrong syntactically in VB.NET. The only thing I can think of off the top of my head is to check, using the IDE, what type Caller is and Caller.name. In VB.NET, it is not case sensitive and many namespaces may be automatically imported without you specifically listing them at the top of the file, so it's quite possible that, in VB, it's using a different type for those than what you expect.