.NET Client unable to call hub methods with array parameters #2672

Closed
midgetspy opened this Issue Nov 1, 2013 · 6 comments

Projects

None yet

4 participants

@midgetspy

I get an exception when I use the .NET Client to to invoke a method on the hub which takes an array as a parameter. I am able to do the reverse (invoke a method on the .NET Client which takes an array) with no issues. I'm using SignalR 2.0.

Steps to reproduce:

Hub:

public class TestHub : Hub
{
    public void OneWordAtATime(string word)
    {
        Clients.All.dataChanged(new string[] { word });
    }

    public void ManyWordsAtATime(string[] words)
    {
        Clients.All.dataChanged(words);
    }
}

Console app with SignalR .NET client:

public class Program
{
    public static void Main(string[] args)
    {
        var hubConnection = new HubConnection("http://localhost:52018/");
        var hubProxy = hubConnection.CreateHubProxy("TestHub");

        Action<string[]> dataChanged = words => 
        {
            Console.WriteLine("Received " + words.Length.ToString() + " words.");
            foreach (string word in words)
            {
                Console.WriteLine("> " + word);
            }
        };

        hubProxy.On("dataChanged", dataChanged);
        hubConnection.Start().Wait();

        string[] wordsToSend = new[] { "one", "two", "three", "four" };
        foreach (string word in wordsToSend)
        {
            hubProxy.Invoke("OneWordAtATime", word).Wait();
        }

        // this fails so I'll just log it
        try
        {
            hubProxy.Invoke("ManyWordsAtATime", wordsToSend).Wait();
        }
        catch (AggregateException ae)
        {
            foreach (Exception e in ae.InnerExceptions)
            {
                Console.WriteLine("Exception: " + e.Message);
            }
        }

        Console.ReadLine();
    }
}

Result:

Received 1 words.
> one
Received 1 words.
> two
Received 1 words.
> three
Received 1 words.
> four
Exception: 'ManyWordsAtATime' method could not be resolved.
@DamianEdwards
Member

Try changing the parameter type to IList instead. This is a limitation in how we discover and bind to methods based on the incoming JSON payload.

@midgetspy

Yeah using IList worked perfectly, thanks. Is this intended behavior that I just missed in the docs or a known issue? Should I leave this issue open?

@davidfowl
Member

This is a documentation thing. Will make sure it gets there.

@davidfowl davidfowl closed this Nov 18, 2013
@styfle
styfle commented Jun 12, 2014

@davidfowl Similarly, I get the same error with a method that has a dictionary as a parameter. Is Dictionary<int,object> supported as a parameter? Where is the list of supported parameter types?

@styfle
styfle commented Jun 12, 2014

It appears the Dictionary parameter does work, however the question still stands about supported parameter types.

@davidfowl
Member

Anything that can be JSON serialized

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment