473,804 Members | 2,191 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<namestoSer ialize = new List<names>();
List.add(...)

XmlSerializer mySerializer = new XmlSerializer(t ypeof(List<name s>));
StreamWriter myWriter = new StreamWriter("m yFileName.xml") ;
mySerializer.Se rialize(myWrite r, toSerialize);
myWriter.Close( );

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

I've tried several XmlInclude(type of(...)) attributes.

Sep 12 '06 #1
4 1818
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"?>
<ArrayOfDeriv ed 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
423
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 classes. namespace FDS.DataCollectionServer.DataProcessing
1
4490
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 : ISerializable { int x; int y; One() {}; // constructor One(SerializationInfo i, StreamingContext c) { // deserialization
3
3179
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. It seems that either I can use default serialization or implement ISerializable. Is there any way to do both (e.g. extend the default serialization). In other words, I want to be able to implement my custom serialization code but call the...
2
8362
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 at deserialization stage, so it's declared not as following: class MyClass : BaseClass { ... }
1
1294
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 properties of the inherited class, not those of the base class. Is there a way to select which properties are to be serialized from my class so that the XML serializer does not bother with the non-serializable base class?
1
1906
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 that inherit from it. How would I configure them for serialization. Do I just put the Serialized setting on the 2 classes or do I also have to put it on the base class. ie.
2
5079
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 a number of other classes, I was assuming that I could just mark them as and use automatic serialization but this does not work (The new class cannot deserialize, because it does not have the correct constructor ie one with arguments...
2
2170
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. at System.Xml.Serialization.StructMapping.FindDeclaringMapping(MemberMapping member, StructMapping& declaringMapping, String parent)
1
1409
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 what I have..! <code> Abstract Class FooBase {
4
11418
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 look at innerException it says: "Cannot serialize member 'System.ComponentModel.Component.Site' of type 'System.ComponentModel.ISite'. OK it is problem to serialize all data so I'll implement my Serialization. I implemented ISerializable...
0
9715
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10600
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10352
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7642
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5535
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3835
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.