David Rutten
David Rutten

Reputation: 4806

Linenumber for Exception thrown in runtime-compiled DotNET code

Not quite the same as this thread, but pretty close.

My program allows people to enter some VB or C# code which gets compiled, loaded and executed at runtime. My CompilerParams are:

CompilerParameters params = new CompilerParameters();
params.GenerateExecutable = false;
params.GenerateInMemory = true;
params.IncludeDebugInformation = false;
params.TreatWarningsAsErrors = false;
params.WarningLevel = 4;

When this code throws an exception I'd like to be able to display a message box that helps users debug their code. The exception message is easy, but the line-number is where I got stuck.

I suspect that in order to get at the line number, I may need to drastically change the CompilerParameters and perhaps even the way these dlls get stored/loaded.

Does anyone know the least steps needed to get this to work?

Upvotes: 1

Views: 687

Answers (1)

TJF
TJF

Reputation: 2258

set OutputAssembly to a temp file, set GenerateInMemory = false, IncludeDebugInformation = true
That should generate symbols and allow you to get a full stack trace with code lines

Upvotes: 2

Related Questions