简体   繁体   中英

stop creating local assemblies when I debug

I have developed ac# 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

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

附加到流程

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM