By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,312 Members | 1,877 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,312 IT Pros & Developers. It's quick & easy.

sub class construtor, super class not holding value

P: n/a
Hi,

I've got a base/super class with just a default constructor. I want another
constructor, but I can't modify the base class, so I created a sub class
with a constructor like so:

public class MySub:MyBase
{
public MySub(string val):base()
{
base.public1="String";
base.public2=val;
}
}

I use it like so:

MyBase myBase=new MySub("sometext");

The class MySub then has no direct references to it, but there is still a
reference to the sub class.

What I'm finding is that if I look at the the value of myBase.public1
under debug (immediately after the assignment has executed), it says Error:
Cannot obtain value, and furthermore, when I try to serialize this class
using XmlSerializer I get an exception:

"An unhandled exception of type 'System.InvalidOperationException' occurred
in system.xml.dll

Additional information: There was an error generating the XML document."

Can someone help me solve the problem?

Thanks

Martin
Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Although the debugger and xmlserializer don't like it, I can correctly
write the base class values to the console.

I reckon this is a xmlserializer issue.

Martin

"Martin" <x@y.z> wrote in message
news:O2**************@TK2MSFTNGP11.phx.gbl...
Hi,

I've got a base/super class with just a default constructor. I want another constructor, but I can't modify the base class, so I created a sub class
with a constructor like so:

public class MySub:MyBase
{
public MySub(string val):base()
{
base.public1="String";
base.public2=val;
}
}

I use it like so:

MyBase myBase=new MySub("sometext");

The class MySub then has no direct references to it, but there is still a
reference to the sub class.

What I'm finding is that if I look at the the value of myBase.public1
under debug (immediately after the assignment has executed), it says Error: Cannot obtain value, and furthermore, when I try to serialize this class
using XmlSerializer I get an exception:

"An unhandled exception of type 'System.InvalidOperationException' occurred in system.xml.dll

Additional information: There was an error generating the XML document."

Can someone help me solve the problem?

Thanks

Martin

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.