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

F

Fett

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
 
G

Guest

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
 
G

Guest

Hi Fett,

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

- Rakesh Rajan
 
F

Fett

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top