The question in short: How can I debug the code generated during a debugging session on the generating program? (see code below)
I am facing the following issue: I would
I finally found a way to workaround it after discovering that my question was a duplicate of How to debug/break in codedom compiled code, which was not obvious for me to find. bbmud gives a very good hint in there to get the debugger working correctly, but doesn't tell how to get into the code. I add a reference to some assembly containing an interface that I want to implement in the scripts:
compilerParams.ReferencedAssemblies.Add(typeof(IPlugin).Assembly.Location);
compilerParams.GenerateExecutable = false; // generate the DLL
// if you want to debug, this is needed...
compilerParams.GenerateInMemory = false;
compilerParams.TempFiles = new TempFileCollection(Environment.
GetEnvironmentVariable("TEMP"), true);
Now when I consider CSharpFriends
being an implementation of IPlugin
, I can get the interface by casting the obj
above:
IPlugin script = obj as IPlugin;
Then debugging calls to interface methods or properties is as easy as usual! The trick of adding
System.Diagnostics.Debugger.Break();
inside the script code also works well but it needs change to the script. As the code inside the application always needs to know what kind of methods are inside the script according to some mechanism (reflexion with attributes or interfaces), using an interface known by both is a very acceptable solution for me.
I hope it helps somebody else.