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

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(strTest!=null);
strTest = "Hello";
// This Assert also fails ?????
Debug.Assert(strTest!=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.LoadFile(strAssemblyPath);
// Instanciate the class and cast the type to the implemented interface
uc = (IWebUseCase) assembly.CreateInstance("MyNamepace.CXmlFileList") ;
// Cast the interface to the base class
m_uc = (CWebUseCase)uc;

// Call the test function
m_uc.testFunction();

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 1844
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(strTest!=null);
strTest = "Hello";
// This Assert also fails ?????
Debug.Assert(strTest!=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.LoadFile(strAssemblyPath);
// Instanciate the class and cast the type to the implemented interface
uc = (IWebUseCase) assembly.CreateInstance("MyNamepace.CXmlFileList") ;
// Cast the interface to the base class
m_uc = (CWebUseCase)uc;

// Call the test function
m_uc.testFunction();

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(strTest!=null);
strTest = "Hello";
// This Assert also fails ?????
Debug.Assert(strTest!=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.LoadFile(strAssemblyPath);
// Instanciate the class and cast the type to the implemented interface
uc = (IWebUseCase) assembly.CreateInstance("MyNamepace.CXmlFileList") ;
// Cast the interface to the base class
m_uc = (CWebUseCase)uc;

// Call the test function
m_uc.testFunction();

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
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...
4
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...
2
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...
2
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 =...
4
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...
8
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...
3
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....
10
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
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...
13
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
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:
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...
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.