Search code examples
c#visual-studiorobotframeworkironpythonvisual-studio-debugging

Breakpoints not hit when C# application called from external program


I am able to call C# methods successfully from Robot Framework using IronPython however I am facing few runtime errors on the C# side which I want to debug using Visual Studio. Is there a way to debug C# application using Visual Studio when its method invoked through external program/script?

I have configured my C# project in Visual Studio using Start External Program (provided the robot executable path and arguments as required by external program). When I started debugging then my external program executes as expected with C# methods also executed successfully. However breakpoints which I have set in the Visual Studio doesn't get hit.

Is there any specifics I am missing while using Start External Program? My python script (external program) is importing DLL from same location where it’s getting generated while building C# project. PDB files also available in the same folder as DLL.


Solution

  • For me breakpoints was not hitting because I haven't attached the correct process. Let me explain in detail for other users to understand the root cause.

    As I mentioned in my question that I was calling C# methods from Robot Framework using IronPython. Therefore I had used robot.exe (Robot Framework executable) as my external program (in the Visual Studio) and I expect my breakpoints to be hit under C# project. However the issue was that C# method executed by ipy.exe (Iron Python) not by robot.exe. It looks like Robot Framework starts ipy.exe process internally and then ipy process invokes C# methods. That means I should have attached ipy.exe process to my C# project so that control will come to Visual Studio whenever breakpoints hit.

    To achieve the same I have done the following. I have inserted Debug.Assert at start of my C# code to halt the execution. Now I have started my external program (Robot Framework Test Case) and then during execution, Message Box appears due to Debug.Assert statement in the C# project. At this moment I have attached the ipy.exe(Iron Python) process to my C# project using Visual Studio using Debug --> Attach to Process. Afterwards when I went ahead with code execution by ignoring the message box then control comes to the breakpoints in the Visual Studio.