问题
Using SignalR (v2.0.2) I'm getting this exception:
Value cannot be null.
Parameter name: o
at Newtonsoft.Json.Utilities.ValidationUtils.ArgumentNotNull(Object value, String parameterName)
at Newtonsoft.Json.Linq.JToken.FromObjectInternal(Object o, JsonSerializer jsonSerializer)
at Newtonsoft.Json.Linq.JToken.FromObject(Object o, JsonSerializer jsonSerializer)
at Microsoft.AspNet.SignalR.Client.Hubs.HubProxy.Invoke[T](String method, Object[] args)
I'm calling the HubProxy with reflection, and I am passing in some null arguments that are triggering this error (aka, some items in the Object[] args
are null). However, passing null for an argument to a method is a perfectly legitimate thing to do. Is this a bug in SignalR in that it is trying to serialize null parameters or is it a bug in Json.NET (v6.0.1) in that it shouldn't attempt to serialize a null object?
回答1:
Turns out this is a known bug in SignalR that has been fixed and will be included in the upcoming 2.2.1 release. See their ticket here.
回答2:
You can try to override SignalR
hubs invocation method, for example:
customize Microsoft.AspNet.SignalR.AuthorizeAttribute
like this:
public override bool AuthorizeHubMethodInvocation(IHubIncomingInvokerContext hubIncomingInvokerContext, bool appliesToMethod)
{
}
Then before invoke, you can check your request and make some processing if needed.
来源:https://stackoverflow.com/questions/22566453/value-cannot-be-null-when-passing-null-arguments-to-signalr-client-side-proxy