Breakpoints not hit when C# application called from external program - c#

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.

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.

Related

Using Visual Studio Debugger with IronPython

I am currently in the dilemma of trying to attach the debugger of Visual studio to a IronPython process.
I have a c# dll that i reference and use in a python scripts, via Ironpython (import clr).
In my c# program i call this python script, again via the IronPython setup.
C# Code to run Python Scripts and its class method
Steps I have done:
So far from the research done into this subject I have figured out that you need to add the options dictionary (as seen in the code) and also disable (Just my code) in the debug options. This should allow one to set a breakpoint in the python scripts which visual studio then can hit. Now this does not work for me in both vs 2019 / vs 2022. Only vs 2017 managed to hit these breakpoints. When I run it with debugger the breakpoints simply say
(The breakpoint will not currently be hit. No symbols have been loaded for this document)
Again from the research done it looks like the fault is that vs 2019 and 2022 do not support the python version that IronPython uses and as such I am slowly giving up on. The overall goal with my project is simply to try to make the debugger work.
Question:
Is there maybe still a way to attach visual studios debugger to a IronPython process and debug the .py file??
PS: I tried both ironPython 2.7 and 3.4.1 alpha
You could add the following code in your script:
import clr
import System
System.Diagnostics.Debugger.Break()
Then run your host .NET application under Visual Studio debugger, then run the script.
The script execution should stop in Visual Studio debugger, where you will be able to step, evaluate, etc.
Also note that IronPython supports standard python tracing mechanism (i.e. settrace). With this, you could implement a custom debugger/tracer for your scripts. For example, we made such an IronPython script debugger as a part of our product called AlterNET Studio.

How to debug a C# console application after it has been activated by SSIS?

I am creating an SSIS package project that will pass a variable into an Execute Process Task. This task is a C# Console application project that I have set to Debug mode. Both of these projects are part of the same Visual Studio 2019 solution.
Although I place several breakpoints throughout the C# code, they never get hit. The SSIS package successfully triggers the console application which then executes successfully without error.
Is there a way to configure SSIS and/or Visual Studio so that the breakpoints in the Console App can be used for debugging?

Debug a C# dll called from C++ (with Mono embedded)

I have a runtime written in C++ (with Mono embedded) which calls functions in a dll written in C# using mono_jit_exec and mono_runtime_invoke. The glue code is generated with CppSharp - which I don't think is relevant here, but just to mention.
So far all good, I can communicate in both directions.
What I want now is to debug the C# code only, using Visual Studio (I'm using the version 2019 on macOS). So in my C# project, I went to Run Configuration and selected the Start external program option pointing to my C++ assembly. After that, I've set some breakpoints, but when I run the C# project in Debug mode, they're never triggered.
Why is not working - is there something else that needs to be done? Is it because Mono is involved?
Ok, so the answer is that is currently not supported.
A workaround would be to do remote debugging using a plugin for Visual Studio or Visual Studio Code, as Unity does.
One available extension is VS Code Mono Debug, which is based on the SDB: Mono Soft Debugger Client.

How to debug and step into a native code project from inside a .NET core C# project?

I am developing a .NET core (.NET Standard 1.6) application in VS2015. The application calls C++ code via P/Invoke. Now I need to step into the C/C++ code of my native dll project.
In regular .NET application, by enabling unmanaged code debugging in the property window of the application, we can step into the C/C++ code directly:
But I can't find such option on a .NET core project. And I know that I can attach the debugger to the application to debug native code only, but that's not suitable for my case.
Again, I want to debug from managed C# code into native C/C++ code.
Any ideas?
Maybe I should switch back to .NET Framework so I can debug the native code. It's really hard to debug by printf. :(
UPDATE
The mixed mode debugging, i.e. debugging from managed C# code into native C/C++ code, has been implemented. See Tutorial: Debug managed and native code in Visual Studio.
UPDATE
The feature may have already been implemented, see this.
Just as #cynic said, this is not yet supported now (2016-11-1).
That can be verified by following steps provided by cynic.
Put a pause in your program (e.g. a Console.ReadKey call).
Attaching to the dotnet.exe process selecting "Managed (CoreCLR)" and "Native" code types
You'll get a message box stating explicitly that "Interop debugging is not supported".
Here is a proper way to debug the native dll.
Right click on the solution, Add Existing Project
Open 'dotnet.exe'. This is normally installed to 'C:\Program Files\dotnet\dotnet.exe'.
You should now see another node in solution explorer for dotnet.exe. Right click it to bring up project properties:
Change the working directory to be what you want
Change the arguments to be the path to your built dll
Change the exe project to your startup project
RECOMENDED: Go to Tools->Options->Projects and Solutions->Build and Run, uncheck 'Only build startup projects and dependcies on Run'

How To Debug A C# Class Library COM Interop Component

I have a C# class library which I also use via COM Interop. To test the library I added a C# test app to the solution, set it to the startup project and I can test it that way. The library works fine this way but one function is not working when called via COM Interop from a Visual C++ 6 test application. How do I debug the library in this situation? I searched for a solution on Google but the only advice I can find is to add a test app to the solution which of course I can't do in this situation.
EDIT: Very sorry. I forgot to say the Visual C++ test application is Visual C++ 6.
First, open boot Visual Studio and Visual C++. Start your test application in VC++. After that, in VS, open the Debug menu and choose the Attach to process. This will show you a list of current process that are running, choose the one corresponding to your test application and click on Attach. This will enabled you to put breakpoint and debug your DLL.

Categories