Tuesday, June 10, 2008

Debug into .Net from VB6

If you've got a VB6 app that is calling a .Net component, and you want to use the VS debugger on the .Net component then you need do the following:

  • Start the VB6 app

  • Set a break point in your .Net app

  • In VS, click on "Tools-Attach to Process..." and select the VB6 application/IDE. This will start your component running in VS.

Now, back in VB6, click the button (or do the action) that activates your .Net component. It will switch into the VS debugger on your breakpoint. Nice!

Be careful about which version of your .Net Dll is registered on the machine (release/debug). If you hav ethe relase one activated then it won't give you any debugging - it does warn you though. To get your debug one back, switch VS back to debug build, close your VB6 app/IDE, and rerun your .Net app. This will re-register the debug version.

For more details, try this.

Update: Very, very, VERY, VERY IMPORTANT!!!! You must enable "Managed Code" debugging when you attach to the process. So, in the "Attach to Process" window, you might have "Automatic: Native Code" showing. This didn't work for me - presumably because my Dll is managed, not native. So click the "Select..." button next to the "Attach to:" and choose "Managed" and "Native". Now attach to VB6.exe and all should work!

No comments: