Tu Roland
Tu Roland

Reputation: 65

How to debug C# program launched from an external exe written in Borland C++Builder

The following is my flow

//''''''''''''                             ''''''''''''
//' Program A' --->Call CreateProcess----> ' Program B'
//' BCB6     '                             ' C# 2010  '
//''''''''''''                             '''''''''''' 

I want to debug Program B in Visual Studio 2010. It is written in C#. I have set Properties -> Debug -> Start External Program to Program A's file path, but I cannot enter the breakpoint in main().

Does anyone know how to solve this issue?

Update: The following is my setting and code. I still cannot understand why I cannot enter the breakpoint in the C# program :-(

image

Upvotes: 1

Views: 2191

Answers (3)

Niv
Niv

Reputation: 31

In addition to MickyD's answer, I had a similar issue where I couldn't load the symbols for the C# app I was trying to debug. The app is launched by an external process.

Process A --> C# app (dll) to debug

Since timing was not an issue in my case, I attached the debugger to the external process. The solution for me was to select the right kind of code type instead of letting the Visual Studio determine it.

Debug -> Attach to Process

Select the right (external) process to attach to.

In "Attach to: Automatic: Native code"

Select... -> Debug these code types

Select the right code type for your project (in my case it was Managed (.NET 4.x) for a .NET Framework 4.7.2 project.

This solution worked for me and I was able to debug my C# app after Visual Studio loaded the right .pdb files that were generated.

Credit to this solution goes to Dan Sinclair from sitecore.stackexchange here

Visual description of the instructions

Upvotes: 0

Uchiha Itachi
Uchiha Itachi

Reputation: 1271

If Program A uses Program B, start Program A; open the solution for Program B in Visual Studio; and go under the debug drop-down and select "Attach To Process". This will let you put in breakpoints and debug through your code. You can also configure your builds to start Program A when you Build/Start Program B in VS, as explained in the answer from User4534....

Upvotes: 0

user585968
user585968

Reputation:

You have it around the wrong way. If you wish to debug the 2nd app (c#) Program B then that is the project you should have loaded up in Visual Studio.

In the debug settings for the c# app, set

Properties -> Debug -> Start External Program to Program A

This will allow you to then set breakpoints in Program B's c# code.

The same thing happens if you are working on a .dll project; you want to set breakpoints in it; but the dll is invoked by an .exe outside of your control (say a native process). You set the Start External Program as above and set the path to the external process.

Alternatively

You can Debug.Attach to Process but that takes careful timing, the process must be running first and you have to cross your fingers that the line in question isn't executed before you are able to set a breakpoint. (Normally you can't set a breakpoint until you attach first)

Upvotes: 2

Related Questions