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

Home Posts Topics Members FAQ

C#: Member variable always null in inherited class! Bug or feature?

Problem: My member variables in the child class are always null. I
don't know why this happens!

I have a base class for handling a user flow in my web, CWebUseCase,
the class is declared like: public class CWebUseCase {...};

This class is inherited into several specific flows like this one
CXmlFileList, which I will use to present a simple list to the user.

//CXmlFileList declaration:
public class CXmlFileList : CWebUseCase, IWebUseCase
{
private string strTest = "Test string";

public void testFunction()
{
// This Assert fails!!!!
Debug.Assert(st rTest!=null);
strTest = "Hello";
// This Assert also fails ?????
Debug.Assert(st rTest!=null);
}
}

The class is instanciated dynamically and the assembly in which the
class resides is also loaded dynamically:

/* Other class which calls the use cases */

// Load the assembly
assembly = Assembly.LoadFi le(strAssemblyP ath);
// Instanciate the class and cast the type to the implemented interface
uc = (IWebUseCase) assembly.Create Instance("MyNam epace.CXmlFileL ist");
// Cast the interface to the base class
m_uc = (CWebUseCase)uc ;

// Call the test function
m_uc.testFuncti on();

Why doesn't the member variable take any values? Does it have anything
todo with the dynamic creation?

Please help me, this "feature" affects an otherwise quit good design of
our application.

Thanks!/Peter

Nov 16 '05 #1
3 1858
Hi Fett,

I would say the best method to extract strings from strings would be by
using Regular Expressions.

Since, in this case you need the value in between the quotes, you could use
the :q construct.

HTH,
Rakesh Rajan

"Fett" wrote:
Problem: My member variables in the child class are always null. I
don't know why this happens!

I have a base class for handling a user flow in my web, CWebUseCase,
the class is declared like: public class CWebUseCase {...};

This class is inherited into several specific flows like this one
CXmlFileList, which I will use to present a simple list to the user.

//CXmlFileList declaration:
public class CXmlFileList : CWebUseCase, IWebUseCase
{
private string strTest = "Test string";

public void testFunction()
{
// This Assert fails!!!!
Debug.Assert(st rTest!=null);
strTest = "Hello";
// This Assert also fails ?????
Debug.Assert(st rTest!=null);
}
}

The class is instanciated dynamically and the assembly in which the
class resides is also loaded dynamically:

/* Other class which calls the use cases */

// Load the assembly
assembly = Assembly.LoadFi le(strAssemblyP ath);
// Instanciate the class and cast the type to the implemented interface
uc = (IWebUseCase) assembly.Create Instance("MyNam epace.CXmlFileL ist");
// Cast the interface to the base class
m_uc = (CWebUseCase)uc ;

// Call the test function
m_uc.testFuncti on();

Why doesn't the member variable take any values? Does it have anything
todo with the dynamic creation?

Please help me, this "feature" affects an otherwise quit good design of
our application.

Thanks!/Peter

Nov 16 '05 #2
Hi Fett,

Sorry...this post was meant for the "getting data..." message :)

- Rakesh Rajan

"Rakesh Rajan" wrote:
Hi Fett,

I would say the best method to extract strings from strings would be by
using Regular Expressions.

Since, in this case you need the value in between the quotes, you could use
the :q construct.

HTH,
Rakesh Rajan

"Fett" wrote:
Problem: My member variables in the child class are always null. I
don't know why this happens!

I have a base class for handling a user flow in my web, CWebUseCase,
the class is declared like: public class CWebUseCase {...};

This class is inherited into several specific flows like this one
CXmlFileList, which I will use to present a simple list to the user.

//CXmlFileList declaration:
public class CXmlFileList : CWebUseCase, IWebUseCase
{
private string strTest = "Test string";

public void testFunction()
{
// This Assert fails!!!!
Debug.Assert(st rTest!=null);
strTest = "Hello";
// This Assert also fails ?????
Debug.Assert(st rTest!=null);
}
}

The class is instanciated dynamically and the assembly in which the
class resides is also loaded dynamically:

/* Other class which calls the use cases */

// Load the assembly
assembly = Assembly.LoadFi le(strAssemblyP ath);
// Instanciate the class and cast the type to the implemented interface
uc = (IWebUseCase) assembly.Create Instance("MyNam epace.CXmlFileL ist");
// Cast the interface to the base class
m_uc = (CWebUseCase)uc ;

// Call the test function
m_uc.testFuncti on();

Why doesn't the member variable take any values? Does it have anything
todo with the dynamic creation?

Please help me, this "feature" affects an otherwise quit good design of
our application.

Thanks!/Peter

Nov 16 '05 #3
hrrrmmm....It seems as it is only the debugger that displays "null" in
the "Tooltips" when the mouse pointer is over the variables...the
Assert statements doesn't fail after all. I still consider this a bug
but now I can get around it!

/Peter

Nov 16 '05 #4

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

Similar topics

8
1894
by: Ernst Murnleitner | last post by:
Hello Readers, Is there a way that only one class can construct a class A and its inherited classes A2, A3 etc.? I want to construct a class A (and the inherited classes A2, A3 etc.) from a (factory) class Fa. I wanted to make that only F can call new A
4
1846
by: lovecreatesbeauty | last post by:
How many member functions will be predefined (provided by compilers implicitly) and called by standard-compliant compilers for a class? Does such a list be given in iso/iec 14882? Which member functions of a base class won't be inherited by derived class? Do all the member functions of a base class predefined by standard-compliant compilers won't be inherited by derived class? - i.e., does the pre-definition mean non-inheritable?
2
7843
by: Mark Sisson | last post by:
Hi all. SITUATION ================ 1. I have a base class with a member variable that's an object 2. I have several classes that inherit from the base class. 3. There are several methods in the base class that modify the member variable 4. I would like to have the inherited classes override the member variable with a new var that's a subclass of the parent's member variable
2
6087
by: Paul Tomlinson | last post by:
The keyword new is required on 'B.IsValid' because it hides inherited member 'A.IsValid' All I have a couple of classes which resemble (sort of!) this: public class A { public bool bIsValid = true; public bool IsValid {
4
2198
by: Fabio Cannizzo | last post by:
Is there a way to hide an inherited protected member so that it is no longer accessible nor visible from the inherited classes? The code below makes c1.foo() no longer accessible, but c2.foo is visible to c3! If instead I make c2.foo private, then c3 will access directly c1.foo Thanks, Fabio class c1 { protected void foo() { MessageBox.Show( "foo: c1" ); }
8
1343
by: Altman | last post by:
I have a class that I want many others inherited off of. I have created a variable in the parent class that I want the inherited classes to set. But I do not want to set the variable in the constructor. Ex. Class A protected myVar as string END Class Class B inherits A
3
5470
by: Wayne Brantley | last post by:
VS2005 RTM Create a web user control to use as a base class for other web user controls. Now, create a new web user control, change the class it inherits from to your base class and compile. (You must have a <% Register %> so it will see it) You will get TWO warnings per class like:
10
2614
by: marcwentink | last post by:
In C++ is it possible to have a class B with a public member int i, and to have a class D that derives from B, and define in that class D a member also named i of type int?
10
1593
by: Dennis Jones | last post by:
Hello, I have a hierarchy of classes in which there will be a data element that is common to all descendant classes. This element (a string in this case) is constant, but specific to each class. So I have something like this: class Base { private: virtual std::string GetString() const = 0;
13
11449
by: Henri.Chinasque | last post by:
Hi all, I am wondering about thread safety and member variables. If I have such a class: class foo { private float m_floater = 0.0; public void bar(){ m_floater = true; }
0
8403
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
8833
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
8737
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
8509
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8610
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
6174
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
4168
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
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2735
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

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.