473,322 Members | 1,846 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,322 software developers and data experts.

Serialization of Inherited Class

Hello... although I've found several posts in reguards to this topic, I don't
seem to understand the solution...

When I derive a class from my base class and then serialize using
XMLSerializer, I do not see the properties of the base class.

Project 1 - Class Library

Public Class nameBase
{
Public string name;
}

Project 2 - WinApp

Public Class names : nameBase
{
Public string location;
}

List<namestoSerialize = new List<names>();
List.add(...)

XmlSerializer mySerializer = new XmlSerializer(typeof(List<names>));
StreamWriter myWriter = new StreamWriter("myFileName.xml");
mySerializer.Serialize(myWriter, toSerialize);
myWriter.Close();

Please help me understand why I don't see the base class name property?

I've tried several XmlInclude(typeof(...)) attributes.

Sep 12 '06 #1
4 1798
Walter,

I was unable to download the project you attached... can you post the code
please.

Thanks,
Mike Slattery

"Walter Wang [MSFT]" wrote:
Hi,

I've tested using a simple solution and it works correctly. I'll attach it
here for your reference. (You may have to use Outlook Express to download
the attachment)

A sample serialized xml file:

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfDerived xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Derived>
<Name>base name</Name>
<Location>url</Location>
</Derived>
</ArrayOfDerived>

Please tell me whether or not my test project works or not. Thanks.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights
Sep 13 '06 #2
Hi Mike,

I'm assuming that your question is not being able to serialize the
properties inherited from base class, right?

The code I'm using is actually the exact code like yours: a class library
have a base class, a control application has an inherited class. So It's
strange that your code doesn't work.

Is it possible that you forgot to assign value to the "name" field? If not
assigned (has null value), it will not be serialized in the resulting xml
file.

By the way, I just checked using Outlook Express that the attachment is ok
to download.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 13 '06 #3
I've confirmed by evaluating the object (in debug mode) and the base class
has all of the properties assigned...

I'm only using Outlook, not outlook express, so I guess I can't seem to get
that attachment, but I don't think it will show my problem... can you email
me and I'll provide my code.

Thanks,
Mike

"Walter Wang [MSFT]" wrote:
Hi Mike,

I'm assuming that your question is not being able to serialize the
properties inherited from base class, right?

The code I'm using is actually the exact code like yours: a class library
have a base class, a control application has an inherited class. So It's
strange that your code doesn't work.

Is it possible that you forgot to assign value to the "name" field? If not
assigned (has null value), it will not be serialized in the resulting xml
file.

By the way, I just checked using Outlook Express that the attachment is ok
to download.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 13 '06 #4
Hi Mike,

I've sent my test project to you via email; please post your result here.
You may send your project to me via email, thanks.
Sep 13 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ron | last post by:
This is as clean as i can get it. Thanks Ron This is the base class that serializes and desrializes the class objects it also provides abstract methodes that are called from its inherited...
1
by: Maheal | last post by:
I have been trying to Serialize an object that is the child of another object which is also serializable. Here is the simplified scenario (assume missing code is correct): class One :...
3
by: Aaron Clamage | last post by:
Hi, I'm not sure that if this is the right forum, but any help would be greatly appreciated. I am porting some java serialization code to c# and I can't figure out the correct way to do it. ...
2
by: Ilya Evseev | last post by:
Hi, folks! There is some class in external library that is declared with attribute. I need to create class inherited from them that should be serializable too. My class uses fields calculated...
1
by: David C | last post by:
I am new to Serialization, so please bear with me. I have a class inherited from a non-serializable class. My goal is to serialize an instance of it to XML and I am only interested in the...
1
by: Glenn Wilson | last post by:
In the current project that I am planning i am thinking of serializing the objects to save as binary files. The question I have is with inheriting classes. If I have 1 base class and 2 classes...
2
by: tony lock | last post by:
I have a class inherited from Control, which I want to serialize, since Control is not Serializable, I have had to implement ISerializable. This works but I now want to inherit this base class into...
2
by: Kevin Burton | last post by:
Hopefully this is the right group. I am getting the following exeption: Member 'PPRP602AType.RPLY_HEADER' hides inherited member 'REPLYType.RPLY_HEADER' , but has different custom attributes....
1
by: R Karthick | last post by:
I am new to serialization. Apologies, if my question sounds really basic. Stuck in this problem for the last two hours. Thought, will ask the experts instead of banging my head more. This is...
4
by: mijalko | last post by:
Hi, I have inherited my class from System.Drawing.Printing.PrintDocument and I wish to serialize this object using XmlSerializer. And I get exception "There was an error reflecting type ...". If I...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.