c# - SignalR Hub + JSON.NET TypeNameHandling: Error resolving type specified in JSON 'System.Linq.Enumerable WhereSelectEnumerableIterator`2 -


i'm working signalr trying .net client calls methods .net on signalr hub. situation objects being transmitted aren't simple value types (string, int, double, etc); can dtos such generic<< t >> or other non-trivial things. need them deserialized same object type when serialized. accomplish this, believe need set json.net typenamehandling "all". believe need on both client , server.

making change typenamehandling on client seems work smoothly, when make change on server, error on server @ connection time, before of requests processed. here how change json.net settings on server:

class startup {     public void configuration(iappbuilder app)     {         var serializer = new jsonserializer()          {              tracewriter = new consoletracewriter(),             typenamehandling = typenamehandling.all,     };      // register signalr can pick     globalhost.dependencyresolver.register(typeof(jsonserializer), () => serializer);      app.usecors(corsoptions.allowall);     app.mapsignalr(); } 

using custom tracewriter outputs console, see following on client:

01:36:55.8596332 - null - changestate(disconnected, connecting) -> msg: started serializing system.linq.enumerable+whereselectenumerableiterator`2[system.collections.generic.keyvaluepa ir`2[system.string,microsoft.aspnet.signalr.client.hubs.hubproxy],microsoft.aspnet.signalr.client.hubs.hubregistrationda ta]. path ''. -> msg: writing type name 'system.linq.enumerable+whereselectenumerableiterator`2[[system.collections.generic.keyvaluepa ir`2[[system.string, mscorlib],[microsoft.aspnet.signalr.client.hubs.hubproxy, microsoft.aspnet.signalr.client]], mscorl ib],[microsoft.aspnet.signalr.client.hubs.hubregistrationdata, microsoft.aspnet.signalr.client]], system.core' syste m.linq.enumerable+whereselectenumerableiterator`2[system.collections.generic.keyvaluepair`2[system.string,microsoft.aspn et.signalr.client.hubs.hubproxy],microsoft.aspnet.signalr.client.hubs.hubregistrationdata]. path ''. -> msg: started serializing microsoft.aspnet.signalr.client.hubs.hubregistrationdata. path '$values'. -> msg: writing type name 'microsoft.aspnet.signalr.client.hubs.hubregistrationdata, microsoft.aspnet.signalr.client' fo r microsoft.aspnet.signalr.client.hubs.hubregistrationdata. path '$values[0]'. -> msg: finished serializing microsoft.aspnet.signalr.client.hubs.hubregistrationdata. path '$values[0]'. -> msg: finished serializing system.linq.enumerable+whereselectenumerableiterator`2[system.collections.generic.keyvaluep air`2[system.string,microsoft.aspnet.signalr.client.hubs.hubproxy],microsoft.aspnet.signalr.client.hubs.hubregistrationd ata]. path ''. -> msg: serialized json: {   "$type": "system.linq.enumerable+whereselectenumerableiterator`2[[system.collections.generic.keyvaluepair`2[[system.st ring, mscorlib],[microsoft.aspnet.signalr.client.hubs.hubproxy, microsoft.aspnet.signalr.client]], mscorlib],[microsoft. aspnet.signalr.client.hubs.hubregistrationdata, microsoft.aspnet.signalr.client]], system.core",   "$values": [     {       "$type": "microsoft.aspnet.signalr.client.hubs.hubregistrationdata, microsoft.aspnet.signalr.client",       "name": "myhub"     }   ] } 01:36:56.4606332 - null - disconnected 01:36:56.4616332 - null - transport.dispose() 01:36:56.4626332 - null - closed 

and server shows this:

-> msg: error deserializing system.collections.generic.ienumerable`1[microsoft.aspnet.signalr.hubs.hubdispatcher+clienth ubinfo]. error resolving type specified in json 'system.linq.enumerable whereselectenumerableiterator`2[[system.collecti ons.generic.keyvaluepair`2[[system.string, mscorlib],[microsoft.aspnet.signalr.client.hubs.hubproxy, microsoft.aspnet.si gnalr.client]], mscorlib],[microsoft.aspnet.signalr.client.hubs.hubregistrationdata, microsoft.aspnet.signalr.client]], system.core'. path '$type', line 1, position 333. -> ex: newtonsoft.json.jsonserializationexception: error resolving type specified in json 'system.linq.enumerable wheres electenumerableiterator`2[[system.collections.generic.keyvaluepair`2[[system.string, mscorlib],[microsoft.aspnet.signalr .client.hubs.hubproxy, microsoft.aspnet.signalr.client]], mscorlib],[microsoft.aspnet.signalr.client.hubs.hubregistratio ndata, microsoft.aspnet.signalr.client]], system.core'. path '$type', line 1, position 333. ---> newtonsoft.json.jsonser ializationexception: not find type 'system.linq.enumerable whereselectenumerableiterator`2[[system.collections.gen eric.keyvaluepair`2[[system.string, mscorlib],[microsoft.aspnet.signalr.client.hubs.hubproxy, microsoft.aspnet.signalr.c lient]], mscorlib],[microsoft.aspnet.signalr.client.hubs.hubregistrationdata, microsoft.aspnet.signalr.client]]' in asse mbly 'system.core, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089'.    @ newtonsoft.json.serialization.defaultserializationbinder.gettypefromtypenamekey(typenamekey typenamekey)    @ newtonsoft.json.utilities.threadsafestore`2.addvalue(tkey key)    @ newtonsoft.json.utilities.threadsafestore`2.get(tkey key)    @ newtonsoft.json.serialization.defaultserializationbinder.bindtotype(string assemblyname, string typename)    @ newtonsoft.json.serialization.jsonserializerinternalreader.resolvetypename(jsonreader reader, type& objecttype, js oncontract& contract, jsonproperty member, jsoncontainercontract containercontract, jsonproperty containermember, string  qualifiedtypename)    --- end of inner exception stack trace ---    @ newtonsoft.json.serialization.jsonserializerinternalreader.resolvetypename(jsonreader reader, type& objecttype, js oncontract& contract, jsonproperty member, jsoncontainercontract containercontract, jsonproperty containermember, string  qualifiedtypename)    @ newtonsoft.json.serialization.jsonserializerinternalreader.readmetadataproperties(jsonreader reader, type& objectt ype, jsoncontract& contract, jsonproperty member, jsoncontainercontract containercontract, jsonproperty containermember,  object existingvalue, object& newvalue, string& id)    @ newtonsoft.json.serialization.jsonserializerinternalreader.createobject(jsonreader reader, type objecttype, jsonco ntract contract, jsonproperty member, jsoncontainercontract containercontract, jsonproperty containermember, object exis tingvalue)    @ newtonsoft.json.serialization.jsonserializerinternalreader.createvalueinternal(jsonreader reader, type objecttype,  jsoncontract contract, jsonproperty member, jsoncontainercontract containercontract, jsonproperty containermember, obje ct existingvalue)    @ newtonsoft.json.serialization.jsonserializerinternalreader.deserialize(jsonreader reader, type objecttype, boolean  checkadditionalcontent) 

it looks json.net can't find class system.linq.enumerable whereselectenumerableiterator`2 . can fix this?


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -