Compiling and Loading C# class on the fly

Compiling and Loading C# class on the fly

am 20.12.2005 05:39:02 von RonJames

I'm trying to compile and load a C# source file "on the fly". The Source
file contains a class (TestCase) that derives from TCBase. TCBase is
defined in the TCUtils assembly. My Solution contains 2 project - TCUtils
and the Main line program.

I'm compiling TestCase using CSharpCodeProvider().CreateProvider and
building an in memory assembly. The source file compiles clean.

I then call CreateInstance on the generated assembly using the name
"TestCase" - the derived class that I've compiled on the fly - and store the
result in a base class reference. Console>WriteLine called with the base
class reference displays the class name of the dervied class, so everything
appears to be workign as I had hoped. However, when I invoke a method on the
base class reference, the base class method is called - not the overridden
method on my derived class.

any help would be appreciated.

thanks

Re: Compiling and Loading C# class on the fly

am 20.12.2005 05:51:59 von Truong Hong Thi

Could you post some source of TestCase to demonstrate the problem?

Re: Compiling and Loading C# class on the fly

am 20.12.2005 15:37:02 von RonJames

I cleaned up my source code so that I could post it, and I've 'fixed' the
problem. Not sure how yet, but now I'll be able to figure it out.

Thanks for you interest.

"Truong Hong Thi" wrote:

> Could you post some source of TestCase to demonstrate the problem?
>
>