My application has a scripting function where I compile an in-memory assembly from a user script using CodeDomProvider.CompileAssemblyFromSource. This is similar to what is described in this answer .
It works very well, but any exceptions that are thrown from the script code do not have line numbers in the stack trace. I tried setting compilerParameters.IncludeDebugInformation = true, but it still does not include line numbers.
Is it possible to get line numbers in exceptions from an assembly in memory?
Here are the key code fragments that I use to compile the assembly:
CompilerParameters compilerParameters =
compilerInfo.CreateDefaultCompilerParameters();
compilerParameters.GenerateInMemory = true;
compilerParameters.GenerateExecutable = false;
compilerParameters.IncludeDebugInformation = true;
...
CodeDomProvider codeProvider = compilerInfo.CreateProvider();
CompilerResults compilerResults =
codeProvider.CompileAssemblyFromSource(
compilerParameters,
new string[] { sourceCode });