PDB file for modifying assembly

Topics: General
Apr 16, 2014 at 9:02 PM
Edited Apr 16, 2014 at 9:36 PM
I wrote a simple console Hello World application. Further, using the Build Task and Roslyn I put a simple call Console.WriteLine and compiled this assembly.
Obviously, after the launch of the modified assembly, I can not debug the application, as PDB file will be a mismatch with the source code.
Whether and how to adapt a PDB file of modified assembly and source code?
Apr 17, 2014 at 5:39 PM
Do you use Compilation.Emit to emit the binary in your build task? If so save the modified source to files on disk, set SyntaxTree.FilePath of the corresponding syntax trees, and then pass a Stream into Emit method to store the new PDB bits and save it to disk.
Apr 17, 2014 at 9:05 PM
Yes I use Compilation.Emit, but I want debug origin source code, not modified. For example: PostSharp rewrite source code and PDB file, and I can debug origin source code. Maybe using Roslyn or using third-party libraries PDB file can be rewritten?
Apr 17, 2014 at 9:22 PM
You need to emit the PDB for the modified code. If you don't want to show the user the modified code you can insert #line directives into the modified code that point the debugger to the original code.
Apr 17, 2014 at 11:06 PM
Oh, thanks, I try this
Apr 18, 2014 at 10:24 AM
Result: It work.
I wrap new code in #line directive. For example:
#line hidden
#line 1
Where Console.WriteLine("A") - new code, Console.WriteLine("B") - code in origin source file.
After, in Visual Studio I disable "Require source files to exactly match the original version" in Debug -> Options and Settings -> General.
Apr 18, 2014 at 4:48 PM
If it works, you shouldn't need to disable "Require source files to exactly match the original version". If you don't do you still get the message?
Apr 18, 2014 at 5:20 PM
I checked again, when option enabled, I can't debug modified assembly.