问题
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