“Value cannot be null” when passing null arguments to SignalR client-side proxy

天涯浪子 提交于 2019-12-08 17:05:48

问题


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

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