Serializing objects to JSON with properties that return interfaces

R

Ra Carter

I want to serialize and deserialize an object to and from JSON. My
code looks something like this:

http://pastebin.com/yB5idwNq

This gives me an error like this:

System.Runtime.Serialization.SerializationException: Type 'MyObject1'
with data contract name 'MyObject1:http://schemas.datacontract.org/
2004/07/namespace' is not expected. Add any types not known statically
to the list of known types - for example, by using the
KnownTypeAttribute attribute or by adding them to the list of known
types passed to DataContractSerializer.

I am only using ISerializable because [Serializable] [DataContract]
would not work of course. The main problem I think I am having is that
I have declared my return type as an interface.

I don't want to change my objects and it is actually important that I
return the interface and not the implementation for various reasons.
What can be done? if Serializable or DataContract attributes won't
work automatically, can I pull this off manually using Serializable?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top