1

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 );

Shachaf.Gortler
  • 5,655
  • 14
  • 43
  • 71

1 Answers1

0

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"

Community
  • 1
  • 1
Shachaf.Gortler
  • 5,655
  • 14
  • 43
  • 71
  • Except that the IParameterResolver is EXACTLY what you want (at least in SignalR v2) - it can do this. I just implemented the ability for my code to accept interface-type parameters of immutable in my SignalR methods. I've also got SignalR's JSON.Net instance customised with a specific type converter, although that's not strictly required for this. – Ian Yates Jun 01 '15 at 05:53