Serialization of Inherited Class

G

Guest

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<names> toSerialize = 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.
 
G

Guest

Walter,

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

Thanks,
Mike Slattery
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 
G

Guest

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
 
W

Walter Wang [MSFT]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top