1

I have the following Code:

 _serializerResponse = MessagePackSerializer .Get<AbstractWebResponse>();

and I try to get the MessagePackSerializer!

But it gives me the following error:

This operation is not supported because 'AbstractWebResponse' cannot be instanciated.

Yes, AbstractWebResponse can not be instaciated, but it's child classes wich I try to serialize (and deserialize) can! And I need it so, because I don't know the type of the Class at deserialization time! Is it not transmited in the data stream so this works?

Jochen Kühner
  • 1,385
  • 2
  • 18
  • 43
  • Say you managed to deserialize to AbstractWebResponse, wouldn't you have lost the child class data anyway? How do AbstractWebResponse and child classes look? – Volkan Paksoy Oct 22 '15 at 13:32
  • I want that I don't get AbstractWebResponse, I want to get a Instance of my Concrete Type! – Jochen Kühner Oct 22 '15 at 15:26
  • Yeah I got that part. What I don't get is how are you expecting to get your concrete type after you deserialize to AbstractWebResponse (as that's what you used in your code). If you post your code it would be more helpful to figure out – Volkan Paksoy Oct 22 '15 at 15:30
  • Yeah this is what I don't know! My Concrete Type derives from AbstractWebResponse so I thought Messagepack can do that in any way (it works like this with JSON.NET, cause JSON.NET can store the Type information in JSON) – Jochen Kühner Oct 22 '15 at 15:45
  • Well, there is no code to work with here but no serializer can instantiate an abstract class. Hope you resolve it. Good luck. – Volkan Paksoy Oct 22 '15 at 16:14
  • The derived Classes are not abstract! It's the same as if you deserialize to a interface! I also could use "object" here! I want to know if messagepack has the type information in it's byte stream or not! and how i can do that! – Jochen Kühner Oct 22 '15 at 19:08
  • I know the derived ones are not abstract but you are trying to deserialize to the abstract one – Volkan Paksoy Oct 22 '15 at 19:27
  • do you have code wich works for derived classes? – Jochen Kühner Oct 22 '15 at 20:16
  • If you use for Example Json.Net and have it configured to include the Type Information in JSON you can Deserialize like I show in the Code! You then have a Variable ob the AbstractType with a instance of the specific type! – Jochen Kühner Oct 24 '15 at 10:13

0 Answers0