0

I have an application that has a startup project (ProjectA) that runs another executable in another Project (ProjectB). When I start the solution with ProjectA as the startup project, I am unable to debug ProjectB. It is unable to load the PDB file even though it is in the directory where its searching.

However, when I start the application and ProjectB is the startup project, I am able to debug it. I assume this is because it is referencing the executable instead of the dll.

Why is this so? How do I get around this so that I can have ProjectA be the startup project and still debug ProjectB?

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
Narbs
  • 35
  • 1
  • 5
  • The following may (or may not) be helpful: [How to: Set multiple startup projects](https://learn.microsoft.com/en-us/visualstudio/ide/how-to-set-multiple-startup-projects?view=vs-2022) – Tu deschizi eu inchid Mar 07 '23 at 17:25
  • Honestly, probably not really the way to do it. Unless you actually need to be able to run projectB directly of course. ProjectB should probably be a class library referenced in ProjectA. Maybe update your question with a little more detail (code examples) about how exactly the two projects interact. – Hursey Mar 07 '23 at 19:20
  • How does ProjectA run ProjectB? How are you trying to debug ProjectB? – Craig Mar 08 '23 at 14:45
  • I would expect that you would need a separate debugger session to attach to the second executable, since I would expect it to be running as a separate process. – Craig Mar 08 '23 at 14:46

1 Answers1

0

As I understand it, your Project A has started the Project B .exe. Something along these lines:

Public Class ProjectAForm
    Private Sub ButtonRunProjectB_Click(sender As Object, e As EventArgs) Handles ButtonRunProjectB.Click
        Process.Start("D:\Github\stackoverflow\multi-project-debugging\project-b\bin\Debug\netcoreapp3.1\project-b.exe")
    End Sub
End Class

You want to debug Project B in this context, but your debugger is attached only to Project A and not to Project B:

not attached


Manual

The interactive way to go about it is with DEBUG\Attach to Process...

attach to process

Now you will hit your breakpoints.

attached


Programmatic

Doing this automatically is tricky but possible. Refer to this answer:

Can I programmatically attach a running .NET 6 process to a running instance of Visual Studio debugger?


Suggestion

If Project A doesn't reference Project B directly (that is, they're completely independent inside a common solution where Project A is the startup) I find that it saves a lot of confusion to have Project B build automatically (if needed) whenever Project A runs. Manually setting project-a to depend on project-b achieves this outcome.

project dependencies

IVSoftware
  • 5,732
  • 2
  • 12
  • 23