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

Problem with IXmlSerializable, inheritance, and xsi:type

I am having trouble using IXmlSerializable within a base class and
having xsi:type work correctly when deserializing an xml file. Here is
a very simplified version of the what is going on in the code:

public class BaseJunkClass : IXmlSerializable
{
public void ReadXml(XmlReader Reader) { }

public void WriteXml(XmlWriter Writer) { }

public XmlSchema GetSchema()
{
return null;
}
}

public class DerivedJunkClass : BaseJunkClass
{
}

public class JunkClassContainer
{
public BaseJunkClass JunkClass;
}

And here is the code to deserialize this:

Type[] JunkTypes = new Type[] { typeof(BaseJunkClass),
typeof(DerivedJunkClass) };

XmlSerializer JunkSerializer = new
XmlSerializer(typeof(JunkClassContainer), JunkTypes);

FileStream JunkStream = new FileStream("JunkConfiguration.xml",
FileMode.Open, FileAccess.Read);

JunkClassContainer TestSerialization =
(JunkClassContainer)JunkSerializer.Deserialize(Jun kStream);

And here are the xml file contents:

<?xml version="1.0" encoding="utf-8" ?>
<JunkClassContainer xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance">

<JunkClass xsi:type="DerivedJunkClass"></JunkClass>

</JunkClassContainer>

After running this code, TestSerialization contains an instance of
type BaseJunkClass, instead of DerivedJunkClass. What's more strange,
is that when this same code runs on the compact framework, it works as
desired. That is, in the compact framework TestSerialization contains
an instance of type DerivedJunkClass.

I came up with a dirty solution to fix this, but I was wondering if
there was a cleaner way. Maybe I'm missing a SerializableAttribute
somewhere, or something additional in the xml file? Any thought or
suggestions would be appreciated.

Thanks.

Apr 24 '07 #1
0 1609

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

Similar topics

8
by: johnsocs | last post by:
How do you validate the following XML document, I'm having problems with element 'one' with the attribute xsi:type="xsd:string" <?xml version="1.0" encoding="UTF-8"?> <zero...
0
by: Umagowder | last post by:
All I have my class serialised correctly. I have to apply style sheet to that data and display it in some other format. Everything works fine,I can not read the following xml tag, ...
0
by: tim.almond | last post by:
I have an arraylist with up to 4 different classes that can be contained. e.g.... <carpark> <car /> <truck /> <motorcycle /> <rv /> </carpark>
0
by: frugalprogrammer | last post by:
I'm pretty sure what I'm up against now is a namespace issue and/or a misunderstanding of how to use SoapVar. From the NetSuite docs, the request should look something like: <soapenv:Body>...
1
by: luthriaajay | last post by:
I am creating an element called 'i:Details' which has an attribute called xsi:type <xsl:element name="i:Details"> <xsl:attribute name="xsi.type"> xsl:text>i:vanilla.stock</xsl:text>...
0
by: =?Utf-8?B?U2hhbm5vbiBCYXJiZXI=?= | last post by:
I have created a schema to write out some configuration data, and the OutPort element uses an abstract complex type (it can be a Message, Discrete, Continuous, Array, etc...). I use the provided...
8
by: robtyketto | last post by:
Greetings, My XML schema defines a customer to be of type UK or Non-UK European making use of xsi:type. The difference between the complex UK and Non-UK European customer types is they have an...
2
by: oh.i.love.spam | last post by:
This is just an example... I don't have the access/ability to upload the actual code. Here is the meat in the XML that is returned from the $client- <VesselConfigurations...
3
by: drajani | last post by:
I have the below input XML sent by APP1. <?xml version="1.0" encoding="UTF-8"?> <abc1:QWAARequest xmlns:abc1="http://www.mysite.com/myLink/v1/Test.xsd" ...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.