【问题标题】:Blazor WebAPI to Client deserialization exception (PocoJsonSerializerStrategy)Blazor WebAPI 到客户端反序列化异常 (PocoJsonSerializerStrategy)
【发布时间】: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


【解决方案1】:

不知道是不是这样,但我对 Blazor 0.7 的经验,仍在申请硕士论文,你不能同时发送或接收嵌套对象。 我的数据库中有 Person 并且那个 Person 有一些商店,所以实体将它映射到类似于这个的对象中 Person{ id:int, name:string, lastName:string, stores:List<Store>} , Store{id:int, name:string, personId:int} 首先必须获取人员,然后使用人员 ID 访问数据库以获取该人员的商店。 不知道为什么,但认为在那个版本中这是不可能的。

【讨论】:

  • 是的,SimpleJson 很简单。但是您可以将 NewtonSoft 包添加到客户端。使用 HttpClient 获取字符串。
猜你喜欢
  • 2015-12-28
  • 2021-02-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-09
  • 1970-01-01
  • 2011-01-08
相关资源
最近更新 更多