A
Andrew Falanga
Hi all,
I have a use case where a list of classes are deserialized to an XML
and serialized from that XML after a system reboot and the program
starts again. The class contained in this list look like this:
class SomeData {
string name;
int size;
}
The class is deserialized and serialized from a generic pointer/
reference in another class which is typed simply as "object." The
deserialization works just fine, and so does the serialization after
the program starts up again. What isn't happening is when I assign
the serialized data, after reboot, to the typed object that is
actually used.
So, for example, I have this:
class SomeClass {
List<SomeData> persistentData;
SomeClass( ) {
if(reentrant)
persistentData = ProgramConfiguration.Instance.Data as
List<SomeData>; // error here
else
persistentData = new List<SomeData>();
}
}
The program doesn't fail anywhere except for when persistentData is
used *after* a reboot. After the reboot, that line produces a null
persistentData object. Why is that?
Originally, the program needed only to know about one SomeData object
and so all that was serialized was one object. That line, where
assignment of the data is done to the "persistentData" object worked,
as you see above. Now, however, a list must be stored and retrieved
from disk. I'm updating the code to accommodate this need, but
although the ProgramConfiguration.Instance.Data object contains that
list, the assignment using as isn't working right and the
persistentData object is null when done.
Any help is greatly appreciated.
Andy
I have a use case where a list of classes are deserialized to an XML
and serialized from that XML after a system reboot and the program
starts again. The class contained in this list look like this:
class SomeData {
string name;
int size;
}
The class is deserialized and serialized from a generic pointer/
reference in another class which is typed simply as "object." The
deserialization works just fine, and so does the serialization after
the program starts up again. What isn't happening is when I assign
the serialized data, after reboot, to the typed object that is
actually used.
So, for example, I have this:
class SomeClass {
List<SomeData> persistentData;
SomeClass( ) {
if(reentrant)
persistentData = ProgramConfiguration.Instance.Data as
List<SomeData>; // error here
else
persistentData = new List<SomeData>();
}
}
The program doesn't fail anywhere except for when persistentData is
used *after* a reboot. After the reboot, that line produces a null
persistentData object. Why is that?
Originally, the program needed only to know about one SomeData object
and so all that was serialized was one object. That line, where
assignment of the data is done to the "persistentData" object worked,
as you see above. Now, however, a list must be stored and retrieved
from disk. I'm updating the code to accommodate this need, but
although the ProgramConfiguration.Instance.Data object contains that
list, the assignment using as isn't working right and the
persistentData object is null when done.
Any help is greatly appreciated.
Andy