Blazor WebAPI to Client 反序列化异常 (PocoJsonSerializerStrategy)



我能够通过Microsoft OData Connector Service Nuget生成代理(使用VS 2017)。这会很好地生成代理。

但是,当我尝试通过网络将实体发送到客户端时,我收到反序列化异常。使用服务引用/代理生成的实体/数据模型是否存在任何技术问题?

下面是从我的 Web API 检索到客户端的有效负载时能够捕获的异常。

System.Reflection.TargetParameterCountException:参数数 指定与预期数量不匹配。在 System.Reflection.RuntimeMethodInfo.ConvertValues (System.Reflection.Binder binder, System.Object[] args, System.Reflection.ParameterInfo[] pinfo, 系统.全球化.文化信息文化, System.Reflection.BindingFlags invokeAttr) <0x34ba990 + 0x00038> in :0在 System.Reflection.RuntimeConstructorInfo.DoInvoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] 参数, System.Globalization.CultureInfo 文化) <0x36f4b28 + 0x0003a> in :0 at System.Reflection.RuntimeConstructorInfo.Invoke (System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] 参数, System.Globalization.CultureInfo 文化) <0x36f49e8 + 0x00016> in :0 at System.Reflection.ConstructorInfo.Invoke (System.Object[] 参数)<0x36f4898 + 0x00016> :0在 SimpleJson.Reflection.ReflectionUtils+<>c__DisplayClass25_0.b__0 (System.Object[] args) <0x3e4a758 + 0x00010> in <8f8c03446dbf45f5bbcb1e109a064f6e>:0 at (包装委托调用) .invoke_object_object SimpleJson.PocoJsonSerializerStrategy.DeserializeObject (System.Object 值,系统类型类型) <0x37ccce8 + 0x00a82> <8f8c03446dbf45f5bbcb1e109a064f6e>:0 在 SimpleJson.PocoJsonSerializerStrategy.DeserializeObject (System.Object 值,系统类型类型) <0x37ccce8 + 0x00862> <8f8c03446dbf45f5bbcb1e109a064f6e>:0 在 SimpleJson.PocoJsonSerializerStrategy.DeserializeObject (System.Object 值,系统类型类型) <0x37ccce8 + 0x00aca> <8f8c03446dbf45f5bbcb1e109a064f6e>:0 在 SimpleJson.PocoJsonSerializerStrategy.DeserializeObject (System.Object 值,系统类型类型) <0x37ccce8 + 0x00862> <8f8c03446dbf45f5bbcb1e109a064f6e>:0 在 SimpleJson.SimpleJson.DeserializeObject (System.String json, System.Type type, SimpleJson.IJsonSerializerStrategy jsonSerializerStrategy) <0x37b6130 + 0x00068> in <8f8c03446dbf45f5bbcb1e109a064f6e>:0 在 SimpleJson.SimpleJson.DeserializeObject[T] (System.String json) <0x3f8b148 + 0x0000a> in <8f8c03446dbf45f5bbcb1e109a064f6e>:0 at Microsoft.JSInterop.Json.Deserialize[T] (System.String json) <0x3f8b110 + 0x00004> in <8f8c03446dbf45f5bbcb1e109a064f6e>:0 at Microsoft.AspNetCore.Components.HttpClientJsonExtensions.GetJsonAsync[T] (System.Net.Http.HttpClient httpClient,

解决

通过使用Henk使用Newstonsoft.Json进行序列化的建议,能够解决此问题。

不知道是不是这样,但我对 Blazor 0.7 的经验是,您不能同时发送或接收嵌套对象。 我的数据库中有 Person,并且该 Person 有一些存储,因此实体将其映射到与此类似的对象中Person{ id:int, name:string, lastName:string, stores:List<Store>} , Store{id:int, name:string, personId:int}首先必须得到人,然后用人的ID去数据库为那个人买商店。 不知道原因,但认为在该版本中这是不可能的。

相关内容

  • 没有找到相关文章

最新更新