473,386 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Deserializing problem in Managed App

emmaUK
2
Hi everyone!

I'm developing a C++/CLR Windows Forms app in visual Studio 05.

I wanted the user to be able to save the current state of the form which I acheived by serializing the form with the code in my 'Save' function:

// I have created a class 'MyPersistantData' to store the forms
// state
// Serialize the form state to an XML file

MyPersistantData^ dat = gcnew MyPersistantData;

TextWriter^ writer = gcnew StreamWriter(saveFileDialog->FileName );
XmlSerializer ^ myXmlSerializer = gcnew XmlSerializer(dat->GetType() );
myXmlSerializer->Serialize( writer, dat );
writer->Close();

This worked great and saved all my form variables to an XML file.

However I am having major problems trying to de-serialize. This is the code in my 'Open' function I have so far:

MyPersistantData^ dat = gcnew MyPersistantData;

XmlSerializer^ myXmlDeSerializer =
gcnew XmlSerializer( dat->GetType() );
FileStream^ reader =
gcnew FileStream(openFileDialog->FileName, FileMode::Open );
XmlReader^ XReader = gcnew XmlTextReader( reader );
// These lines are fine.

// But the following line throws an exception during runtime:

dat = dynamic_cast< MyPersistantData^ >
(myXmlDeSerializer->Deserialize( reader ) );

Do I need to overload the assignment operator for this class or is there something else i need to do?

Cheers

Emma
Oct 16 '06 #1
2 1472
Banfa
9,065 Expert Mod 8TB
Do I need to overload the assignment operator for this class or is there something else i need to do?
Understanding that I have little experience of .NET 2.0 (and the little experience I have makes me shudder, Microsoft appear to to trying to burry the real code in Windows so far under their absraction layers that they no longer resemble actual C++).

Anyway, you may need to overload the assignment operator in MyPersistantData, but only really if it contains pointer members with allocated data. Also I would not really have expected the lack of an assignment operator to cause an exception imediately but to cause one further down the line when it is harder to detect.

I would look to the exception you are getting, it should give you some clues as to what is going on, Deserialize can raise an exception so it may be how you are using the class.

Good Luck.
Oct 16 '06 #2
emmaUK
2
Thankyou Banfa

I have narrowed the problem down somewhat. Remember that I can get it to Serialize fine but just not De-Serialize.

If I remove the following line of code from my persistant class it NOW De-Serializes so this data member is the problem:

ListBox::ObjectCollection^ listBoxItemsCollection;

So deserializing the ObjectCollection handle is causing the problem.

Seems strange that it Serializes this ok.

Any Ideas?

Emma.
Oct 16 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Justin Armstrong | last post by:
I'm having difficulties deserializing some objects. Consider the following example of what I'm trying to do: ---------------------------------------------------------- class Person { string...
1
by: Thomas | last post by:
Hi, I implemented a composite pattern which should be serializable to xml. After spending some time in the newsgroups, i finally managed serializing, even with utf-8 instead of utf-16, which...
4
by: Wayne Wengert | last post by:
Using VB.NET I want to read in an XML file that has an array of objects and then step through the resulting array in code. I build a class to define the structure and I am running code to read in...
2
by: Earl Teigrob | last post by:
I am saving and restoring value types such as Int32, DateTime and Boolean in strings. I was wondering if there is a mechanism build into .NET for serializing and deserializing these to string...
1
by: Bob Rock | last post by:
Hello, always having to validate an XML stream against a XSD may add up an important overhead. My XMLs are usually the result of serializing a class instance and often in my applications what I...
5
by: Daniel Gackle | last post by:
I'm getting a strange ArgumentNullException after deserializing a SortedList. Haven't seen this discussed in the newsgroups, but it looks like a bug - unless I missed something obvious? I've...
6
by: Steve Teeples | last post by:
I use serialization to write class data to a file. During my development of this class I need to add properties or fields on occation. After adding a property, when deserializing the data saved...
0
by: Sivajee Akula | last post by:
Hello All, I am trying to consume a .NET Service from Adobe LiveCycle Workflow. The service deals with complex objects. I am getting the following exception at the time of invocation of the...
1
by: =?Utf-8?B?SmVyZW15X0I=?= | last post by:
I am working on an order entry program and have a question related to deserializing nodes with nested elements. The purchase order contains multiple line items which I select using an...
0
by: ullner | last post by:
I have an XML fil that looks like this: <Environment> <AreaOfInterest> <Name>ScenarioMap</Name> <UpperRight> <GDC> <Latitude>-179</Latitude> ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.