473,657 Members | 2,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sub class construtor, super class not holding value

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="S tring";
base.public2=va l;
}
}

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.Invalid OperationExcept ion' 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
1 4147
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******** ******@TK2MSFTN GP11.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="S tring";
base.public2=va l;
}
}

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.Invalid OperationExcept ion' 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1433
by: Shaun Marshall | last post by:
Hope someone can help, for an assignment i was given a starter application package, with that starter package i had to create some employee classes and test harnesses. below iv pasted my Container class, which holds a company eomployee class , the Company class and the Data holding class. I am somehow trying to pass the container class into the preset frame as seen in the attached file (Jdeveloper package file) hope someone can give some...
2
3768
by: Ovid | last post by:
Hi, I'm trying to determine the cleanest way to override class data in a subclass. class Universe { public String name; private static double PI = 3.1415; Universe(String name) {
8
2341
by: Pent | last post by:
Hi All, Why is this code valid? How can the static ctor be used? It doesn't act as class ctor at all. struct A { static A() { } }
4
1812
by: Pupeno | last post by:
Hello, I want to jump over a method in the class hierarchy, that is: If I have class A(object), clas B(A), class C(B) and in C, I want a method to do exactly what A does but not what B does in its reimplementation, would it be correct to do: super(A, super(B, self)).method() in C ? Thank you. -- Pupeno <pupeno@pupeno.com(http://pupeno.com)
4
1716
by: ddtl | last post by:
Hello everybody. Consider the following code: class A(object): def met(self): print 'A.met' class B(A): def met(self):
3
2795
by: Belebele | last post by:
I have an Element class which is abstract and I would like to have an object of the Iterator class to iterate over a range of elements. I would like to use std::for_each to instrument the iteration, which forces me to have certain interface on the Iterator class. struct Element { virtual ~Element() = 0; };
4
1410
by: GesterX | last post by:
Hi guys, this has been bugging me for a while and I'd appreciate any help anyone could offer. Basically I am running a boating simulation and I have all of the "harder" parts done but one error is holding me back from compiling my code. I won't go into detail about the simulation but basically I have a Boat super class and extended from this are the sub classes; cruiser, speedboat, and jetski. My problem is when it comes to accessing...
1
6487
by: madman228 | last post by:
Hi guys I have run in to a littl bit of trouble. I am writing a class called polynomial in which i need a derivative method I have everything, just dont know how to start the derivative method. Any help will be appriciated here is the code: import java.io.*; import java.util.Scanner; public class Polynomial extends UnorderedArrayList { Scanner sc = new Scanner(System.in); //Default constructor
11
6238
by: Rafe | last post by:
Hi, I'm working within an application (making a lot of wrappers), but the application is not case sensitive. For example, Typing obj.name, obj.Name, or even object.naMe is all fine (as far as the app is concerned). The problem is, If someone makes a typo, they may get an unexpected error due accidentally calling the original attribute instead of the wrapped version. Does anyone have a simple solution for this?
0
8411
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
8323
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
8613
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6176
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
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
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...
1
2740
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
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.