【发布时间】:2019-10-26 09:45:42
【问题描述】:
我能够通过 Microsoft OData 连接器服务 Nuget 生成代理(使用 VS 2017)。这会生成代理就好了。
但是,当我尝试通过网络将实体发送到客户端时,我得到了反序列化异常。使用服务参考/代理生成的实体/数据模型是否存在任何技术问题?
以下是当负载从我的 Web API 检索到客户端时我能够捕获的异常。
System.Reflection.TargetParameterCountException:参数数量 指定的数字与预期的数字不匹配。在 System.Reflection.RuntimeMethodInfo.ConvertValues (System.Reflection.Binder 活页夹,System.Object[] args, System.Reflection.ParameterInfo[] pinfo, System.Globalization.CultureInfo 文化, System.Reflection.BindingFlags invokeAttr) in :0 在 System.Reflection.RuntimeConstructorInfo.DoInvoke (System.Object obj, System.Reflection.BindingFlags 调用Attr,System.Reflection.Binder 活页夹,System.Object[] 参数,System.Globalization.CultureInfo 文化) 在:0 在 System.Reflection.RuntimeConstructorInfo.Invoke (System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder 活页夹,System.Object[] 参数,System.Globalization.CultureInfo 文化) 在:0 在 System.Reflection.ConstructorInfo.Invoke (System.Object[] 参数) 在 :0 在 SimpleJson.Reflection.ReflectionUtils+c__DisplayClass25_0.b__0 (System.Object[] args) 在 :0 在(包装器委托调用) .invoke_object_object 在 SimpleJson.PocoJsonSerializerStrategy.DeserializeObject (System.Object 值,System.Type 类型) 在 :0 在 SimpleJson.PocoJsonSerializerStrategy.DeserializeObject (System.Object 值,System.Type 类型) 在 :0 在 SimpleJson.PocoJsonSerializerStrategy.DeserializeObject (System.Object 值,System.Type 类型) 在 :0 在 SimpleJson.PocoJsonSerializerStrategy.DeserializeObject (System.Object 值,System.Type 类型) 在 :0 在 SimpleJson.SimpleJson.DeserializeObject (System.String json, System.Type 类型,SimpleJson.IJsonSerializerStrategy jsonSerializerStrategy) 在 :0 在 SimpleJson.SimpleJson.DeserializeObject[T] (System.String json) 在 :0 在 Microsoft.JSInterop.Json.Deserialize[T] (System.String json) 在 :0 在 Microsoft.AspNetCore.Components.HttpClientJsonExtensions.GetJsonAsync[T] (System.Net.Http.HttpClient httpClient,
已解决
能够通过 Henk 的建议使用 Newstonsoft.Json 进行序列化来解决此问题。
【问题讨论】:
-
Blazor 服务器端还是 Blazor 客户端?什么实体给什么客户?
-
异常通常包含有用的信息。你应该分享它。
-
@KirkWoll - 已更新异常消息。谢谢。
-
您谈到“发送到客户端”,这表明问题出在服务器上。但 SimpleJson 仅用于客户端。
-
这样的问题需要大量的代码和更多的描述。
标签: connector service-reference blazor new-webserviceproxy