Visual Studio: how to debug a library using an external executable?

I am developing a class library. The library should be used by another -.exe program without source code. The location of the library file is passed as a parameter to this exe, for example, by running: prog.exe lib.dll

I would like to debug the library using this .exe (using debugging tools like breakpoints, etc.). How to use Visual C # for this?

I found a possible way to create a single-line program that executes prog.exe lib.dll . Surely there is a better way?

+6
debugging visual-studio class-library visual-c # -express-2010
source share
3 answers

In the debugging options of the project, select "Run external program" and enter the path to exe. When debugging starts, VS starts exe, connects to it as a debugger.

When your library is loaded, all breakpoints on your code are activated.

One caveat: with an external program, make sure it loads the DLL you are building, things can be (at best) odd if they load a different version that does not match the source code.

+2
source share

If you already have an external program using your library (which is also a .net application, I assume), you can run this program and attach a debugger to the process (Debug β†’ Attach to process in the menu). Then you can set breakpoints in the class library code and debug it. Make sure exe uses the dll and pdb file that is synchronized with your code (latest build).

+1
source share
  • You can probably try windbg. with the sos extension, anything you can do with Visual Studio is possible.
  • If you want to debug a library, then why can't you load this library into the exe that you created, and step by step inside the library,
0
source share

All Articles