Reputation: 65
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 :-(
Upvotes: 1
Views: 2191
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
Upvotes: 0
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
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.
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