1

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?

Community
  • 1
  • 1
David Rutten
  • 4,716
  • 6
  • 43
  • 72

1 Answers1

2

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

TJF
  • 2,248
  • 4
  • 28
  • 43
  • Thanks Tom, I was afraid that was the answer. Now I have to figure out a way to delete all those dll and pdb files *after* my application shuts down... Any ideas on that? – David Rutten Oct 12 '09 at 02:39
  • 1
    just create them in the Windows Temp directory so windows takes care of it: Path.GetTempFileName() – TJF Oct 12 '09 at 02:45
  • That's where I put them, but that folder is close to 1 Gig on my machine, if someone is taking care of it they're doing a sloppy job... – David Rutten Oct 12 '09 at 02:47
  • 1
    hm, Windows might not clean that up until it 'feels' it has to. You could always create a separate folder and set the OutputAssembly = "mytempfolder" + Path.GetRandomFileName() Then just clean it up everytime the application launches or shuts down – TJF Oct 12 '09 at 02:55
  • That's a good solution. The File delete will fail if there is still an instance of my app that is using a dll, so I can wipe all unused dlls in my own temp folder on run. – David Rutten Oct 12 '09 at 02:58
  • Windows doesn't automatically clean up files placed in the Temp directory. `Path.GetTempFileName()` only generates a temporary file; it does nothing to clean up when you're done using it. See the [documentation](https://msdn.microsoft.com/en-us/library/system.io.path.gettempfilename%28v=vs.110%29.aspx). – Ken White Feb 05 '15 at 20:18