2

I have developed a c# class library which I need to debug with an external program.

So I set the "start external program" of this project to my external program and then I start the debugger.

The problem is that this assembly is also located (as a copy) in the root-dir of this external program. When I start the debugger it will load both assemblies: the one from the bin-dir and the one from the root-dir of the external program.

The result is an TargetInvokationException because the containing types are located in two different assemblies.

How can I prevent visual studio to load both assemblies?

Best regards Tobias

Jester
  • 56,577
  • 4
  • 81
  • 125
Tobias Koller
  • 2,116
  • 4
  • 26
  • 46

2 Answers2

0

If you have trouble with start external process, you can go the other way and attach to process.

Make sure that you compile a debug version of your dll and copy the .pdb file into the executable folder along with the dll to get optimal results

Attach to process

Then you just need to locate the application process that you want to debug

Chris Schaller
  • 13,704
  • 3
  • 43
  • 81
  • hm...this would work ...but its more complicated than simply debug the application :) If I won't find another solution I will use yours – Tobias Koller Jan 31 '18 at 14:14
  • In scenarios like this your first line of defence is unit tests. Write tests against the common or critical methods that your other application is using and this should minimise the amout of time you have to 'live' debug. I write a lot of dlls that are consumed by legacy applications over COM+ so I understand the pain for sure. – Chris Schaller Jan 31 '18 at 14:20
0

i finally made it like this:

  1. I've created a post-build-event where I ...
    • ...copy the assemblies to the external program
    • ...copy the assemblies to a directory where every project copies their assemblies (and only create references to these assemblies and NOT to any project directly
    • ...delete the assembly in the debug-directory

here is my script:

  robocopy "$(TargetDir)\" "..\..\..\..\..\..\USD" "$(TargetFileName)"
  robocopy "$(TargetDir)\" "..\..\..\..\..\..\USD" "$(TargetName).pdb"


  robocopy "$(TargetDir)\" "..\..\..\..\..\..\Lib\myassembly1" "$(TargetFileName)"
  robocopy "$(TargetDir)\" "..\..\..\..\..\..\Lib\myassembly1" "$(TargetName).pdb"

del "$(TargetFileName)"

      REM ignoriert faulty interpretation of 1 Return-Code from robocopy
      set/A errlev="%25ERRORLEVEL%25 & 24"
      exit/B %25errlev%25

like described above I changed all direct project-references to the assembly-files in the lib-directory.

now I'm able to debug my project by starting the external program. No TargetInvokationException occurs anymore.

Tobias Koller
  • 2,116
  • 4
  • 26
  • 46