I can attach the debugger and get it to break - but it has trouble finding the .cs file, I think LinqPad deletes it as part of its build.. 8-(
            Asked
            
        
        
            Active
            
        
            Viewed 1.0k times
        
    41
            
            
        - 
                    1Note that after this question was asked, Linqpad introduced a new, premium edition of Linqpad which includes its own debugger. – Brian Apr 22 '15 at 17:05
3 Answers
49
            If you call
Debugger.Launch();
Debugger.Break(); 
to initiate the breakpoint within your LINQPad script, LINQPad will guess that you want to use VS to debug your script and won't delete the .cs file.
 
    
    
        Chris Weber
        
- 5,555
- 8
- 44
- 52
 
    
    
        Joe Albahari
        
- 30,118
- 7
- 80
- 91
- 
                    1I just had another go with a C# Program like this 'code'void Main() { Debugger.Launch(); int i = 0; Debugger.Break(); i.Dump(); }'code' VS launches fails to find the code. BUT then running again from LP, VS then find the the .cs file.... – Mesh Apr 06 '11 at 16:05
- 
                    I was having trouble with this, then realized I was trying to attach a VS 2008 debugger to LINQPad.exe; it *has* to be a version of VS that supports .NET 4+ (such as VS 2012). – Cᴏʀʏ Jun 01 '15 at 19:59
25
            
            
        - Start LINQPad
- In VS, open Debug -> Attach to Process...
- Choose LINQPad.exe
- Set breakpoint in your code called by LINQPad C# code, or write Debugger.Break() in your LINQPad script where you want the debugger to halt.
- Execute the script from LINQPad and watch the magic.
 
    
    
        jornhd
        
- 309
- 3
- 12
- 
                    3You should check Debugger.IsAttached property before calling Debugger.Break(). – Tormod Sep 30 '13 at 16:06
3
            
            
        If your LINQPad code is calling a method in some referenced C# assembly and you want to debug that assembly in Visual Studio 2015, this worked for me:
- Build your solution.
- Optionally, run your LINQPad script, let it crash, etc. In the lower right LINQPad status bar, notice the PID in light blue coloring.
- In VS, CTRL + ALT + P to attach to process. Attach to the LINQPad UserQuery process with the PID you saw.
- Place a breakpoint here in VS.
- Run the linqpad query and pop over to VS. You should hit your breakpoint!
 
    
    
        Christopher
        
- 10,409
- 13
- 73
- 97
 
    