简体   繁体   中英

SignalR client Side Json serializer

I have the following

class A : ISomthing{}

Class B : ISomthing{}

interface ISomthing{}

Class C { public ISomthing _member {get;set}}

and i try to send the following object from my .net signalR client to my hub ,I'm using signalR 2.0.2

C obj = new C();
obj._member  = new A();

I receive the following error ,Could not create an instance of type ISomthing . Type is an interface or abstract class and cannot be instantiated.

In my client and server side I'm using JsonSerializer.TypeNameHandling = TypeNameHandling.Auto;

Update : The object can be serialized by it self, using the signalR serializer : var textWriter = new StringWriter(); _hubProxy.JsonSerializer.Serialize(textWriter, obj );

Apparently this is not currently supported , see my question here

And the answer I got : "The DependencyResolver has an IParameterResolver registered which is responsible for deserializing server-side inputs. The IParameterResolver is implemented by DefaultParameterResolver which does not use the JsonSerializer registered the DependencyResolver. msdn.microsoft.com/en-us/library/jj919135(v=vs.118).aspx"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM