Search code examples
connectorservice-referenceblazornew-webserviceproxy

Blazor WebAPI to Client deserialization exception (PocoJsonSerializerStrategy)


I am able to generate a proxy (using VS 2017) via the Microsoft OData Connector Service Nuget. This generates the proxy just fine.

However, when i try to send a entity over the wire to the client side, i get a deserialization exception. Is there any technical issues using service reference/proxy generated entities/data-models?

Below is the exception i was able to capture when the payload is retrieved from my Web API to the client.

System.Reflection.TargetParameterCountException: Number of parameters specified does not match the expected number. at System.Reflection.RuntimeMethodInfo.ConvertValues (System.Reflection.Binder binder, System.Object[] args, System.Reflection.ParameterInfo[] pinfo, System.Globalization.CultureInfo culture, System.Reflection.BindingFlags invokeAttr) <0x34ba990 + 0x00038> in :0 at System.Reflection.RuntimeConstructorInfo.DoInvoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x36f4b28 + 0x0003a> in :0 at System.Reflection.RuntimeConstructorInfo.Invoke (System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x36f49e8 + 0x00016> in :0 at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) <0x36f4898 + 0x00016> in :0 at SimpleJson.Reflection.ReflectionUtils+<>c__DisplayClass25_0.b__0 (System.Object[] args) <0x3e4a758 + 0x00010> in <8f8c03446dbf45f5bbcb1e109a064f6e>:0 at (wrapper delegate-invoke) .invoke_object_object at SimpleJson.PocoJsonSerializerStrategy.DeserializeObject (System.Object value, System.Type type) <0x37ccce8 + 0x00a82> in <8f8c03446dbf45f5bbcb1e109a064f6e>:0 at SimpleJson.PocoJsonSerializerStrategy.DeserializeObject (System.Object value, System.Type type) <0x37ccce8 + 0x00862> in <8f8c03446dbf45f5bbcb1e109a064f6e>:0 at SimpleJson.PocoJsonSerializerStrategy.DeserializeObject (System.Object value, System.Type type) <0x37ccce8 + 0x00aca> in <8f8c03446dbf45f5bbcb1e109a064f6e>:0 at SimpleJson.PocoJsonSerializerStrategy.DeserializeObject (System.Object value, System.Type type) <0x37ccce8 + 0x00862> in <8f8c03446dbf45f5bbcb1e109a064f6e>:0 at SimpleJson.SimpleJson.DeserializeObject (System.String json, System.Type type, SimpleJson.IJsonSerializerStrategy jsonSerializerStrategy) <0x37b6130 + 0x00068> in <8f8c03446dbf45f5bbcb1e109a064f6e>:0 at 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,

Resolved

Was able to resolve this by using Henk's suggestion of serializing using Newstonsoft.Json.


Solution

  • Don't know if it is that, but my experience with Blazor 0.7, still working on application for master thesis, is that you can't neither send or receive nested object at once. I have Person in my database and that Person has some stores, so entity maps it in object similar to this one Person{ id:int, name:string, lastName:string, stores:List<Store>} , Store{id:int, name:string, personId:int} and first had to get person and then go to database with id of person to get stores for that person. Don't know reason why but think that in that version it is not possible.