rdotnet / rClr

R package for accessing .NET
63 stars 28 forks source link

Unable to debug C# code from Visual Studio while called from R through rClr #32

Closed tvidvei closed 5 years ago

tvidvei commented 7 years ago

I'm trying to debug C#-methods that are called from R through rClr. I have set the VS-project to start Rscript.exe (Properties | Debug | Start external program), with the filepath to my R-script as Command-line argument. When I press F5 in VS, Rscript.exe runs the R-script as expected, but the execution doesn't stop at my breakpoints. When I redirect the output from the R-session to a file (by adding "> output.tmp" to the R-script file in the command-line argument field), I can see that my C#-method is called and returns the expected result. Why doesn't the execution stop at the breakpoints?

For details and an example: Se my question at StackOverflow: https://stackoverflow.com/questions/46038019/how-to-debug-c-sharp-code-called-from-r-by-rclr

jmp75 commented 7 years ago

This should work; there are a variety of reasons this may not, starting with out of sync binaries, or somehow VS not debugging .NET but only native. A workaround, and possibly what you really want is to attach VS to an already running R interpreter (Debug - Attach to process) and make sure VS is told to debug Managed Code: image

tvidvei commented 5 years ago

Thank you!

I write the solution here "for the records":

Using Debug | Attach to Process ... from VS works fine! When using RStudio one should attach to the process rsession.exe, not rstudio.exe.

Regards, Tor Vidvei