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?

4
  • 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)
    – user2819245
    Jun 21, 2017 at 16:25
  • "The executable has been attached to the file"? That does not make sense. You can attach a debugger to the executable. Jun 21, 2017 at 21:15
  • Visual Studio IMHO cannot debug child processes. Other debuggers like WinDbg can, see .childdbg Jun 21, 2017 at 21:16
  • Sorry I will fix that, I meant I attached it to the process.
    – hgrov52
    Jun 22, 2017 at 11:40

2 Answers 2

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.