Deserialization with WriteXml/ReadXml

Posts   
 
    
ChBaeumer
User
Posts: 175
Joined: 23-Oct-2003
# Posted on: 06-Nov-2009 10:34:45   

Hi,

I have following error here:

Following code:


CommonEntityBase entityBase = entityCore as CommonEntityBase;
CommonEntityBase cloneEntityBase = ( CommonEntityBase ) entityBase.GetEntityFactory( ).Create( );

string xmlData = string.Empty;
entityCore.WriteXml( out xmlData );
cloneEntityBase.ReadXml( xmlData );

During the WriteXml-Method some properties of type object are marked within the code as 'Type="Unknown"'. Due to this the ReadXml-Methods throws an NullReferenceException during read in method FieldUtilities.DetermineRealFullTypeName(...)

Any hints?

Using Version 2.6.9.903

Thanks

Christoph

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 06-Nov-2009 10:49:15   

entityCore.WriteXml( out xmlData );

What's the type of the entityCore object?

ChBaeumer
User
Posts: 175
Joined: 23-Oct-2003
# Posted on: 06-Nov-2009 10:54:05   

One of the generated entities which has CommonEntityBase as base class

I'm currently looking into it. One mistake was not to mark runtime properties as [NonSerialized]. But this did not solve the error with the object property.

Edit:

Ups, I've discovered that Properties can't be mark as 8NonSerialized]

So how can I exclude specific Properties from being serialized?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 06-Nov-2009 11:05:15   

What's the .NET type of the property which has type generated as UnKnown? Could you please post the piece of XML holding the "unknown" value?

ChBaeumer
User
Posts: 175
Joined: 23-Oct-2003
# Posted on: 06-Nov-2009 11:41:55   

Ok I figured it out.

To prevent Properties from being serialized you have to mark them as [System.Xml.Serialization.XmlIgnore].

In this case I have following code:


        private object additionalInformation = null;
        public object AdditionalInformation
        {
            get { return this.additionalInformation; }
        }

Attributing the Property AdditionalInformation with the statement above solved my problem.

Thanks for your time walaa

Christoph