469,126 Members | 1,281 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,126 developers. It's quick & easy.

XMLSerializer & Inheritence

Help!

I want to serialize mu C# objects uzing the xmlserializer
class. It works well whem all my classes are flat, but
when I use inheritence to split the data and
implementation I get an "unknown element" exception.

namespace A
{
[System.Xml.Serialization.XmlRootAttribute("thing",
Namespace="urn:thing", IsNullable=false)]
public class thing
{
public string name;
}
}
namespace B
{
public class thingUser : A.thing
{
public void doStuffwiththing();
}
}

I want to deserialize B.thingUser but it fails! How do I
get round this?

TIA

Mark

Nov 11 '05 #1
3 1334
Mark Turner wrote:

public class thingUser : A.thing
{
public void doStuffwiththing();
Did you mean
public void doStuffwiththing() {}
I want to deserialize B.thingUser but it fails! How do I
get round this?


--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2
The example was retyped for clarity, pointing out a
typing mistake is hardly helpful!

basically the problem is with the XmlSerializer getting
its knickers in a twist. I cant see why it should have a
problem but seemingly if i have the 2 classes named the
same but in different namespaces it has a hard time
figuring out the attributed of the subclass.

any pointers?
-----Original Message-----
Mark Turner wrote:

public class thingUser : A.thing
{
public void doStuffwiththing();


Did you mean
public void doStuffwiththing() {}
I want to deserialize B.thingUser but it fails! How do I get round this?


--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

.

Nov 11 '05 #3
an*******@discussions.microsoft.com wrote:
The example was retyped for clarity, pointing out a
typing mistake is hardly helpful!


I just copied your code and pasted it to VS.NET. Aftetr fixing that typo
I run the serializer on b.thingUser class with no any hitch. When name
property is set it's serialized as b.thingUser member.
Provide more info about exception you are getting.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Cindy Liu | last post: by
1 post views Thread by Zion Zadik | last post: by
1 post views Thread by Lloyd Dupont | last post: by
5 posts views Thread by =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.