Unmanaged Debugging vs. Managed Debugging vs. Mixed Debugging.


All versions of VS support debugging both managed and unmanaged code.  However there is a big difference between doing one or the other and doing both. GreggM has written about some of the reasons interop debugging is difficult.  Here I will refer to debugging both managed and unmanaged at the same time as Mixed debugging.


 


If you are having stability problems when debugging, one reason may be you are doing Mixed debugging without realizing it.  If you have a C# or VB project that uses unmanaged COM objects, at some point you may have wanted to debug into the COM object.  Somewhere along the line someone right clicked on the project in the Solution Explorer, went to properties, then “Configuration Properties/Debugging/Enable Unmanaged Code”, and set it to true.  If you did this, you enabled Mixed debugging.  There are some cool features you get with that, and some features you lose.  On balance Mixed debugging is almost never worth it.  Mixed is more intrusive, and less stable then either approach alone.  If you are debugging a Managed Application you should not turn on ‘unmanaged debugging’ unless you have a specific need for it.  One great feature of using managed or native debugging alone is you can attach and detach at will.  One of the features you lose with Mixed is the ability to detach.


 


If you attach to a process it will default to debugging all program types in the process.  Don’t accept this default!  If you attach in Mixed mode “Common Language Runtime” and “Native” are both checked. Pick one, if you don’t like what you picked, detach and reattach with the other.  Your life will be much easier.


 


C# and VB projects do not have a way to turn off managed debugging.  If you want to native debug a application that starts from a managed exe, my suggestion is to leave the original project as managed only, and create an additional project to do your native debugging. The most versatile way is to create an empty VC++ makefile project. Right click on the solution, Add/ New Project/ Visual C++/Makefile Project.  Right click on the new project Properties/Debugging/Debugger Type.  There are 4 choices: “Native only”, ”Managed Only”, “Mixed”, and “Auto”.  Use Native only.  Never use Auto.  A few rows up is “Command”, left click to get a dropdown with Internet Explorer, ActiveX container, regsvr32 and browse.  Pick browse and find the .exe output of your current startup project.  Finally in the top right of this property dialog is a button “Configuration Manager”.  Click on it and you will see a list of the projects in the Solution with configuration, platform, and check box on whether it should build.  Uncheck the build box for the makefile project you just created.  At this point you can set the makefile project to be the startup project: Right click on the Project /Set as Startup Project.  You will now launch in native debugging mode.  You can either switch statup projects or switch the Debugger Type setting in the makefile project to switch back and forth.  You can also detach when debugging this way and reattach with the other debugger type.  This is typically more flexible, stable, and productive.

Comments (123)

  1. Saurabh Jain says:

    An easier way is to right-click on solution node, choose add project and then navigate to your exe and add it. .EXE is a recognized C++ project type. You still have to follow the steps mentioned above. Of course, you do need C++ installed as part of your VS setup.

  2. Steve Steiner of the MS debugger team tells

    why.

  3. Hi. I have a mixed project (C++ Managed library) that uses managed and unmanaged code. I am having problems in debugging native (unmanaged) code. The breakpoints don’t work (when I put one in the native code, appears a “?” ) and I can not give a “step into” for native codes. It is intriguing that some native codes debug works well, but for most of it, it doesn’t.

    This C++ library do not use others libraries, just native codes. It is used for a C# .Net application.

    I have changed the "debuger type" option from Mixed to Native Only, but this did not help. I have checked the Assembly files path already.

    What can be wrong that makes me unable to debug native C++ code?

  4. Mark Turner says:

    I have the exact same problem as Eliseu.  Has anyone figured out a solution?

  5. Torbjørn says:

    Eliseu – I am also experiencing this problem…and I still haven’t found a solution…

  6. Steve Steiner of the MS debugger team tells why .

  7. Very many thanks for a good work. Nice and useful. Like it!

  8. Trish,Trish says:

    Good job, great site! This I found in internet <a href="http://beyonce-knowles-nude.blogspot.com/ ">Beyonce</a> [url=http://beyonce-knowles-nude.blogspot.com/]Beyonce[/url] bye!

  9. You have great site, impressive! Look at mine <a href="http://hometown.aol.com/celebrityseek/paris-hilton.html ">Paris Hilton</a> or [url=http://hometown.aol.com/celebrityseek/paris-hilton.html]Paris Hilton[/url] bye!

  10. You have great site, impressive! Look at mine <a href="http://hometown.aol.com/celebrityseek/paris-hilton.html ">Paris Hilton</a> or [url=http://hometown.aol.com/celebrityseek/paris-hilton.html]Paris Hilton[/url] bye!

  11. …is verry good idea! Good site, all you need is LOVE !!! (Beatls)

  12. Alex says:

    http://www.mscracks.com – software cracks, serial numbers, keygens, patches, cd keys, activation codes

  13. Thank you for your site. I have found here much useful information!Very cool design!Added to favorites!! My site: http://titan-tankless-waterheater.blogspot.com

  14. lexus says:

    Good site… visit my site about LEXUS!

    http://lexus.vipautocatalog.info

  15. suvcatalog says:

    The Site is excellent! Great job!  Visit My blog about A sport utility vehicle, or SUV.

    http://myblog.es/suvcatalog

    [url=http://myblog.es/suvcatalog]suv catalog: used suv[/url]

  16. Jonn says:

    Good site! Great design… and respect webmaster!

    visit my blog about my car http://myblog.es/cadillacsuv I like Cadillak!

    [URL=http://myblog.es/cadillacsuv]cadillacsuv[/URL]

  17. Wonderful and informative web site.I used information from that site its great.

    My Catalogue site of Biker jacket leather

    http://solisearch.net/bloghoster/?u=siniy

  18. Donna says:

    Today was a complete loss. I feel like a fog. I’ve just been hanging out doing nothing, but eh…

  19. Joe says:

    Your site looks great! Would you please also visit my homepage?

    <a href=  ></a> [url=][/url]

  20. Linda says:

    I’ve just been letting everything pass me by lately. I’ve more or less been doing nothing. Not much going on lately. I can’t be bothered with anything recently.

  21. Mikle says:

    Good site! Well.. i like design!

  22. Besid,Besid says:

    Very good project! <a href= http://www.debtconsolidation.newov.info >debt consolidation</a> <a href= http://www.badcreditloan.newov.info >bad credit loan</a>

  23. Qest,Qest says:

    Very nice resources!<a href= http://www.mortgagerefinancing.newov.info  >mortgage refinancing</a> <a href= http://www.autoinsurancequote.newoz.info >auto insurance quote</a>

  24. Milas says:

    Well…good news, i like your site, Happy new year! )))

  25. Tonik says:

    Well, your site is very good, good news and design…! ))) Happy Christmas! SmilerMan.

  26. Ocis,Ocis says:

    Very nice resources!<a href= http://betting.ggfix.com >betting</a> <a href= http://wagering.ggfix.com >wagering</a>

  27. Jonn says:

    Happy New Year! real good site!

  28. Dingo says:

    real good news! good site, respect webmaster!

  29. Elisa says:

    Hi there! Your site is cool, indeed! Visit my sites, please:

    <a href=  ></a> [url=][/url]

  30. Fred,Fred says:

    Perfect site, i like it! <a href= http://docs.google.com/View?docid=df2wwh2p_7c7mc89 >Debt Consolidation</a> [url=http://docs.google.com/View?docid=df2wwh2p_7c7mc89]Debt Consolidation[/url]  goodbye

  31. Katrina says:

    Hi there! Your site is cool, indeed! Would you please also visit my homepage?

    <a href= http://fm7.biz/0l6t >ephedra</a> [url=http://fm7.biz/0l6t]ephedra[/url]

  32. shutgunst1 says:

    Over the last month I have been busy doing [url=http://www.linkwizard.net]link exchange[/url] and  getting links back to my site. Mainly reciprocal, directories, search engines and a few one-way back links.

    I ran the link report in Web CEO for my index page which gave the following results:

    MSN 234 – Yahoo 11 – Google 0.

    Now, this is telling me something. Is it that MSN are not so fussy as the other two in recognising any form of link back as an authority for the website. Thereby making it easier to obtain top ranking positions for chosen keyword phrases that are the anchor text in the link.

    If so, to be successful with Yahoo and Google do you have to concentrate on getting top quality, relevant one-way back links. Like making sure the site that has a link to you uses your keywords in their title and anchor text etc. And that sites that link to that site also have keyword relevant content/links etc.

    This isn’t taking into account on-page optimization.

    I await your comments with interest.

  33. The excellent site!!! Want you good luck!!!,The excellent site!!! Want you good luck!!!,The excellent site!!! Want you good luck!!!,The excellent site!!! Want you good luck!!!

  34. Bill says:

    More information, you work, stress, then you focus on a creative. Appraisal discussion, ask figure of his new overcome, or off to describe. Foundation for them out the basic level, this regularly undertake a [url=http://learnin.43i.net ]learning center.[/url].

  35. Linkin park says:

    Best my wishes to Admin. Plz look my site too:

    <a href=http://linkin-park.creablog.com>linkin”>http://linkin-park.creablog.com>linkin park concert ticket</a> | [url=http://linkin-park.creablog.com]linkin park concert ticket[/url] | http://linkin-park.creablog.com – linkin park concert ticket !  Thanks.  p.s. Linkin Park Concert Ticket

  36. The excellent site!!! Want you good luck!!!,The excellent site!!! Want you good luck!!!,The excellent site!!! Want you good luck!!!,The excellent site!!! Want you good luck!!!

  37. This is a wonderful page for everyone! Please visit my homepage:

    [@../doorway/blogspot/tr3.txt||10||p-11||3||,

    This is a wonderful page for everyone! Please visit my homepage:

    [@../doorway/blogspot/tr3.txt||10||p-11||3||

  38. The excellent site!!! Want you good luck!!!,The excellent site!!! Want you good luck!!!,The excellent site!!! Want you good luck!!!,The excellent site!!! Want you good luck!!!

  39. Very well! Your site is neat! Please visit my site too:

    [@../doorway/blogspot/tr10.txt||7||p-1||1||,Very well! Your site is neat! Please visit my site too:

    [@../doorway/blogspot/tr10.txt||7||p-1||1||

  40. Caverta says:

    I have already enjoy your website, and it is so nice and cool. I will visit your website again. Thank you. Please More updates

  41. Young Jeezy says:

    Looks great! I found lots of intresting things here. I will visit your website again.

    http://jeezy.blogcu.com/ Young Jeezy

  42. Young Jeezy says:

    Looks great! I found lots of intresting things here. I will visit your website again.

    http://jeezy.blogcu.com/ Young Jeezy

  43. Young Jeezy says:

    Looks great! I found lots of intresting things here. I will visit your website again.

    http://jeezy.blogcu.com/ Young Jeezy

  44. Buy xenical says:

    I have already enjoy your website, and it is so nice and cool. I will visit your website again.

    <a href= http://xenicalonline.blogcu.com >Xenical</a>

    [url= http://xenicalonline.blogcu.com ]Xenixal[/url]

  45. Buy Premarin says:

    Looks great! I found lots of intresting things here. Many thanks. Nice site. Cheers!

  46. I just want to say thank you for taking the time & effort for put this web page together! Please visit my homepage:

    ,

    I just want to say thank you for taking the time & effort for put this web page together! Please visit my homepage:

  47. Buy Zantac says:

    Looks great! I found lots of intresting things here. Many thanks. Nice site. Cheers!

  48. Doxycycline says:

    Re: <a href=http://medjetnet.info/doxycycline/buy-doxycycline.html>Doxycycline</a>”>http://medjetnet.info/doxycycline/buy-doxycycline.html>Doxycycline</a> is used to treat bacterial infections, including pneumonia and other respiratory tract infections; Lyme disease; acne; infections of skin, genital, and urinary systems; and anthrax (after inhalational exposure). It is also used to prevent malaria. Doxycycline is in a class of medications called tetracycline antibiotics. It works by preventing the growth and spread of bacteria. Antibiotics will not work for colds, flu, or other viral infections.

    [URL=http://medjetnet.info/doxycycline/buy-doxycycline.html]buy doxycycline[/URL]|

  49. plavix says:

    Nice site! Cheak my site to! It is fresh idea i think 😉

    <a href= http://plavix.stormloader.com >plavix</a>

  50. Hi Sam! You letter i received. Thanks! Photos is nice!!! ,Hi Sam! You letter i received. Thanks! Photos is nice!!!

  51. Lucy! Please call me,Lucy! Please call me

  52. Lucy! Please call me,Lucy! Please call me

  53. Britneywpfgn says:

    Very nice! I have some LJ with news, check this out:

    <a href= http://iwantubadlyz.livejournal.com >Newest news</a>

    <a href= http://annakubat.livejournal.com >Check this out</a>

    <a href= http://jackie_simpson.livejournal.com >livejournal</a>

  54. Wried says:

    Very nice! I have some sites with news, check this out:

    <a href= http://nuhost.info >Politics news</a>

    <a href= http://susearch.info >Lastest news</a>

    <a href= yanasearch.info >Lifestyle news</a>

  55. estate says:

    visit us, i could found very usefull information

  56. domai says:

    domai archive domai diana domai elle

  57. Buy Evista says:

    This is really fresh idea of the design of the site! I seldom met such in Internet. I will visit your website again. Good Work dude!

  58. Buy Evista says:

    This is really fresh idea of the design of the site! I seldom met such in Internet. I will visit your website again. Good Work dude!

  59. The Best Catalog.

    <a href=http://healthpiece.info/>Real”>http://healthpiece.info/>Real Catalog</a>[url=http://healthpiece.info/]The Real Catalog[/url]

  60. Britneyhlhpd says:

    <a href= http://www.angelfire.com/indie/cucone >a ture story</a> <a href= http://www.angelfire.com/hiphop/hugole >a2 size inches</a> <a href= http://www.angelfire.com/goth/qoxuxa >a thousand miles piano music sheet</a> <a href= http://www.angelfire.com/funky/pimeho >a e slide topper</a> <a href= http://www.angelfire.com/punk/dimyxi >a jaffe wedding rings</a>

  61. Blow Job says:

    My compliments to a very nice website. I found lots of intresting things here. Many thanks. Good Work dude!

  62. Hi Sam! Photos i send on e-mail.

    Green,Hi Sam! Photos i send on e-mail.

    Green

  63. Hi Sam! Photos i send on e-mail.

    Green,Hi Sam! Photos i send on e-mail.

    Green

  64. My compliments to a very nice website. I found lots of intresting things here. p.s. More How To Have you don’t take it acknowledges that shirt looks like more intimate than men.

  65. "It’s not because of fate, it’s because of Tequila"  That may be the best thing I have ever read in my whole life!

  66. Looks great! I found lots of intresting things here. Please more updates.

  67. passtest says:

    How to pass a drug test ? Answers – http://pass-a-drug-test.org

  68. Buy Valium says:

    Very good website you have here, After the visit I put my step in to your guestbook.

  69. Buy Valium says:

    Good site! It very impressive, easy to find helpful information. Keep up the great work.

  70. Buy Valium says:

    Looks great! I found lots of intresting things here. Please more updates.

    http://valium1.blogcu.com/ Buy Valium

  71. Buy Valium says:

    "It’s not because of fate, it’s because of Tequila"  That may be the best thing I have ever read in my whole life!

    http://valium1.blogcu.com/ Buy Valium

  72. Buy Caverta says:

    Good Work dude! I will visit your website again.

  73. Buy Caverta says:

    This is really fresh idea of the design of the site! I seldom met such in Internet. Good Work dude!

  74. Buy Caverta says:

    Site – very comprehensive and meticulous from all sides, its good! Just excellent website, I sure!

  75. Buy Caverta says:

    Good site! It very impressive, easy to find helpful information. Keep up the great work.

  76. ga2kuqvh73 says:

    dyeq5m86nm2518nq <a href = http://www.516888.com/1042058.html > vezacgbk </a> [URL=http://www.570414.com/272754.html] bmfcmg9e9fd0ldde [/URL] 13e2weaih

  77. Buy Caverta says:

    "It’s not because of fate, it’s because of Tequila"  That may be the best thing I have ever read in my whole life!

  78. Great site and excellent resource you have. I think it’s very cool. I will visit your website again. Thank you!

  79. Bill says:

    <a href= http://www.beepworld.it/members/videoculrr >video culi</a>   [url=http://www.beepworld.it/members/videoculrr]video culi[/url]   <a href= http://www.beepworld.it/members/wallpnatrr >wallpapers natalizio</a>   [url=http://www.beepworld.it/members/wallpnatrr]wallpapers natalizio[/url]  

  80. Yuhong Bao says:

    There are disadvantages to doing this. For example, you cannot get a mixed callstack, managed-only debugging cannot be used with Image File Execution Option due to the OS not knowing that it is a debugger starting the process and detach will continue the program (this one is not a disadvantage, just something to keep in mind). But if you don’t need to debug both the managed and the native code at the same time, it is a good idea to not use mixed debugging. If you do need to use mixed debugging on a managed program, set it back once you finish. As the article said, sometimes people forget to do this.

  81. On  <a href=http://groups.google.at/group/erykah9803/web/klingeltne-selber>klingelt�ne selber</a> muck keno seconds call tilt <a href=http://groups.google.at/group/erykah9803/web/klingeltne-zum-downloaden>klingelt�ne zum downloaden</a> push hand pasadena hole <a href=http://groups.google.at/group/xaviera7608/web/klingeltne-zum-anhren>klingelt�ne zum anh�ren</a> variance line front city card vigorish?

  82. Are ez money payday loan 100 loan online payday