Possible SignalR bug in Xamarin Android

混江龙づ霸主 提交于 2019-12-11 07:51:23

问题


When using Xamarin Android application as a SignalR client, I encountered this strange behaviour. Having:

    public GameClient()
    {
        _connection = new HubConnection("url");
        _proxy = _connection.CreateHubProxy("GameHub");

        _proxy.On("SendMove", (string playerID, string fromID, string toID, int actions, int lastUpdate) =>
        {
            if (OnMoved != null)
                OnMoved(playerID, actions, fromID, toID, lastUpdate);
        });

causes System.MissingMethodException: Method not found: 'Microsoft.AspNet.SignalR.Client.HubProxyExtensions.On'.. But when I removed just a single parameter right in the middle of the method:

    _proxy.On("SendMove", (string playerID, int actions, string destinationID, int lastUpdate) =>
            {
                if (OnMoved != null)
                    OnMoved(playerID, actions, destinationID, lastUpdate);
            });

then everything works just fine. One would think that the error is caused by the number of parameters - that, maybe, SignalR has some limitation. But, I got the same error with this method:

        _proxy.On("SendGameJoined", (object xDoc) =>
            {
                if (OnGameJoined != null)
                    OnGameJoined(this, xDoc);
            });

Just a single parameter and again the same error. Now, the solution - or, rather workaround - to this one is quite simple again. Changing object to string helped immediately.

        _proxy.On("SendGameJoined", (string xDoc) =>
            {
                if (OnGameJoined != null)
                    OnGameJoined(this, xDoc);
            });

Now, SignalR documentation says, that there can be any number of parameters of any types - even custom ones. I am using just common C# types and yet I have this strange behaviour. Am I doing something wrong? Or is it a bug in SignalR, or Xamarin?

来源:https://stackoverflow.com/questions/27669362/possible-signalr-bug-in-xamarin-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!