MethodInfo Invoke - getting source line number after TargetInvocationException

D

dbwNick

Hallo,
I have a problem getting the line number of an exception thrown in an
executable generated using ICodeCompiler (from a source text file) and
then invoked.
I catch the TargetInvocationException in Invoke, but line number of
where the exception in the ICodeCompiler executable is thrown is
missing! However assemblies referenced by this executable can show
line numbers (if debug versions)
All that is said regarding the code compiled is that the exception was
at Main().
CompilerParameters.IncludeDebugInformation is set to True
Source snippet shown below:
Thanks for any help,
Nick

CompilerParameters cp = new CompilerParameters(assemblynames);
cp.GenerateExecutable = true;
cp.GenerateInMemory = true;
cp.IncludeDebugInformation = true;

TempFileCollection tfc = new TempFileCollection();
CompilerResults cr = new CompilerResults(tfc);
cr = icc.CompileAssemblyFromFile(cp, fileName);

If successful I invoke using:
System.Reflection.MethodInfo m = cr.CompiledAssembly.EntryPoint;
try{
m.Invoke(null, null);
}
catch(TargetInvocationException tie)
{
Console.WriteLine(tie.ToString());
Console.WriteLine(tie.InnerException.ToString());
}
 
D

dbwNick

Further clarification to my earlier posting:
If I generate an executable file with:
CompilerParameters cp = new CompilerParameters(assemblynames,
"File.exe");
Then run File.exe I see the line number of where the exception was
thrown.
However invoking the same executable from memory with

System.Reflection.MethodInfo m = cr.CompiledAssembly.EntryPoint;
m.Invoke(null, null);

as detailed in previous message does not provide the source file name
and line number.
Nick
 

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

Similar Threads


Top