By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,001 Members | 1,504 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,001 IT Pros & Developers. It's quick & easy.

Deserialization of objects containing arrays of unknown size

P: n/a
I have a class which uses three other classes, two of which are used in
arrays. This class is only ever used for incoming messages. All classes
inherit from ISerializable and impliment GetObjectData(). All classes use
the [Serializable] attribute and have a default constructor.

When deserializing from an xml string that represents a complex object, I am
getting NullReferenceExceptions that seem to be related to the arrays. The
object is created using the default constructor so the array sizes are
unknown and not constructed. The content is only populated when deserialized.

Using SerializationInfo in a constructor in the manner
_header=(IspecHeader)info.GetValue("Header",this.H eader.GetType()); does not
seem to populate the child object even for items that are not arrays.

For the arrays I am trying to use code like
_lincList=(IspecRow[])info.GetValue("LincList",this.LincList.GetType()) ; in
the constructor of the parent object.

The assignments in both the above are to private variables that are used by
Properties.

How can I deserialize a complex object? Serialize works just fine at parent
object level for all its children. With deserialization to what extent does
each child class need to handle its serialization and how is it called. I
currently have all classes inheriting from ISerializable, implimenting
GetObjectData() and an Overloaded constructor using SerializationInfo and
StreamingContext.

When I Unit Test this the deserialize does not throw an exception.
When I try and access objects that should be populated it throws a
NullReferenceException.

When I try to serialize after a deserialize it returns xml that does not
contain any child information.

I am at a loss and the examples are too simplistic and not real world enough.

Any help would be very much appreciated. I will supply code if required.

cheers

PeterW
Dec 15 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.