New Posts New Posts RSS Feed: InvalidDataContractException
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

InvalidDataContractException

 Post Reply Post Reply
Author
splace View Drop Down
Newbie
Newbie


Joined: 28-Sep-2010
Location: Nanaimo B.C.
Posts: 5
Post Options Post Options   Quote splace Quote  Post ReplyReply Direct Link To This Post Topic: InvalidDataContractException
    Posted: 07-Dec-2011 at 11:26am
I get the following exception during application start up.

Type 'DateRangeObject' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.  If the type is a collection, consider marking it with the CollectionDataContractAttribute.  See the Microsoft .NET Framework documentation for other supported types 

This is occurring when trying to load the Metadata from the .ibmmx file. It is throwing the exception in a function called SerializationFns.RestoreDCS(...).

Do I have to annotate my classes with the [DataContract] attribute in Code First? I thought the [ProvideEntityAspect] generated the appropriate serialization code. Do you also have to annotate with the other attributes as well? [Binding] [Display] etc?

BTW it appears that DateRangeObject class is not the serialization file but is passed to the DataContract serializer as a KnownType.

Not sure if this helps but DateRangeObject is an abstract class.

Thanks for any help,
Sandy 


Edited by splace - 07-Dec-2011 at 11:54am
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 08-Dec-2011 at 12:33pm
When the metadata file is loaded, we do deserialize its contents using the DataContractSerializer.  We're passing to the serializer the full list of "known" types, the same list we'd pass when doing other serialization/deserialization, including moving data between the client and server.  So, although it seems a bit odd since this type isn't part of the Code First model, you can think of it as the early warning, which would otherwise come later.
 
Any known type must be serializable:  this can mean marking it up with DataContract/DataMember attributes, or ensuring that it has a public constructor.
 
It's possible that this type doesn't need to be included as a known type, though.  Are you explicitly marking it as a known type?
 
As for the ProvideEntityAspect attribute, it does not actually mark up the CF entity class with DataContract/DataMember attributes.  The class must still be serializable, but these attributes aren't strictly required. 
 
You can find more information on known types and serialization here - http://drc.ideablade.com/xwiki/bin/view/Documentation/knowntypes.
 
 
 
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down