About Dynamic Code Generation

  • Thread starter Thread starter Ghada Al-Mashaqbeh via DotNetMonster.com
  • Start date Start date
G

Ghada Al-Mashaqbeh via DotNetMonster.com

Hi all,

I am facing a problem in dynamic code generation at run time, the problem
occurs when the dynmaic code use global data exist within the original
application.
Lets say that my application is called "Dynamic Code", so the name space in
my project is "Dynamic Code", I have created "Form1.cs" where my code exist.
Form1 class contain a global class "xarray" with static memeber "x" which is
an array, I want the added dynamic code by the end user to use this array.

I have included "using DynmaicCode;" in the generated dynamic code, in the
assembly references added to the compiler parameters I have written the
Following code:

param.ReferencedAssemblies.Add("Form1.dll"); // param is the copiler
parameters object.

to enable the use of array x in the dynamic code, the above code is written
in Form1.cs, the problem is when compiling the added code the compiler give
me an error that Form1.dll does not found, What shall I do to enable the use
of Global data within the project by the run timr added code???

waiting a reply plz.

Ghada
 
Exactly what error is being generated? Does it say

error CS0006: Metadata file 'Form1.dll' could not be found

or something else? Are you referring to a CompilerResults.Errors
entry or a thrown exception? Are all your dll's in the same directory
as the running executable? If not then you'll need to use fully
qualified paths to all dll's.

HTH,

Sam
 
Ghada said:
I am facing a problem in dynamic code generation at run time, the problem
occurs when the dynmaic code use global data exist within the original
application.
Lets say that my application is called "Dynamic Code", so the name space in
my project is "Dynamic Code", I have created "Form1.cs" where my code exist.
Form1 class contain a global class "xarray" with static memeber "x" which is
an array, I want the added dynamic code by the end user to use this array.

I have included "using DynmaicCode;" in the generated dynamic code, in the
assembly references added to the compiler parameters I have written the
Following code:

param.ReferencedAssemblies.Add("Form1.dll"); // param is the copiler
parameters object.

to enable the use of array x in the dynamic code, the above code is written
in Form1.cs, the problem is when compiling the added code the compiler give
me an error that Form1.dll does not found, What shall I do to enable the use
of Global data within the project by the run timr added code???

You can try:

param.ReferencedAssemblies.Add(System.Reflection.Assembly.GetExecutingAssembly().Location);

which include full path to the call assembly.

Arne
 
Back
Top