jeudi 19 février 2015

Trouble with "Assembly.EnrtyPoint.Invoke" [C#]

I have the following problem:

I am compiling C#-code at runtime using the CSharpCodeProvider in Microsoft.CSharp. The created application runs perfectly, if I double-click on the generated file.


If, however, I am loading my created assembly with Assembly.Load and invoking the entrypoint-method with Assembly.Load("...").EntryPoint.Invoke(null, null), I get a NullReferenceException.




The NullReferenceException is referring to the value of the .EntryPoint-Property.

When I debug the variable containing the loaded Assembly, VisualStudio shows the following:

Error

Larger image


The error is in German and means The value of "local" or argument "asm" is not available in this instruction pointer and can therefore not be determined. It may have been removed during optimization.




I want to add at this point that my generated assembly is not optimized (I also added the compiler argument /optimize-, which prevents optimization.)


I performed an other test to determine the error source by trying this Code:

Assembly asm = Assembly.LoadFile(Assembly.GetExecutingAssembly().Location);

asm.EntryPoint.Invoke(null, argv);


This code is also throwing a NullReferenceException at the line containing the Invoke-call.




Does someone here know, where this error is coming from and I can solve it?

Thank you very much :)




Aucun commentaire:

Enregistrer un commentaire