0

I have two C# projects, one is trying to run the other as a process. The master project starts the process of the other like this:

ProcessStartInfo info = new ProcessStartInfo(filepath, args);
info.Verb = "runas";
info.UseShellExecute = true;
if (file.Exists(filepath))
{
    _fileID = Process.Start(info).Id;
}
else
{
    throw new Exception("Could not find file.exe at " + filepath);
 }

The project that is being started as a process builds into a console application and only contains one .cs file which only has a Main().

The process should immediately run this Main method, however I set a breakpoint on the first line of the main method and it never gets hit. The executable has been attached to the process created from the master project, and the file path is correct.

My question is if I am debugging this process correctly, and if there is a better way to debug a project file inside of a process?

hgrov52
  • 119
  • 1
  • 5
  • You could also just debug this other process on its own. Set up its debug command line arguments the same as they would be passed by the code of your first project (i.e., whatever the content of the *args* variable)... There should not really be any need to execute/start project #1 if you want/need to debug project #2. By the way, if your 2nd program always needs to be run with elevated privileges, you can better enforce this by setting up the application manifest accordingly ([see here](https://stackoverflow.com/questions/2818179/how-do-i-force-my-net-application-to-run-as-administrator)) –  Jun 21 '17 at 16:25
  • "The executable has been attached to the file"? That does not make sense. You can attach a debugger to the executable. – Thomas Weller Jun 21 '17 at 21:15
  • Visual Studio IMHO cannot debug child processes. Other debuggers like WinDbg can, see `.childdbg` – Thomas Weller Jun 21 '17 at 21:16
  • Sorry I will fix that, I meant I attached it to the process. – hgrov52 Jun 22 '17 at 11:40

2 Answers2

0

One way to debug would be: Open your Console application project in Visual Studio In the project properties, for Debug, set the "Start external program" to your master project's exe

Now, if you Debug this project, your break point should be hit

Subbu
  • 2,130
  • 1
  • 19
  • 28
0

You need to attach to the other process. You can do it from VS.

Go to Debug -> Attach to process and select yours on the list.

enter image description here

Paweł Łukasik
  • 3,893
  • 1
  • 24
  • 36