Debugging a OneNote Toolbar Addin (C#)

I was just asked this question internally and I thought I would share with everyone:

Can I debug the OneNote add-in within Visual Studio? I tried to attach OneNote.exe but it did not stop at any breakpoint.

I wanted to let people know that you can debug one of these powertoys, here's some notes for debugging a C# OneNote toolbar addin:

  1. When OneNote runs your toolbar addin your app is not running on OneNote.exe instead we are using COM and a DLL surrogate.
  2. The app which has the DLL surrogate is actually DllHost.exe
  3. You want to attach the debugger to the DllHost.exe process when you addin is running
  4. Since the addins normally start/stop quickly you can add MessageBox.Show command at the beginning of your code
  5. When you click on the button in OneNote you will see your message box popup, during this pause attach your debugger to DllHost.exe
  6. Debug away!

If anyone has any problems or needs help please let me know.  I answered this internally and I wanted to make sure external people knew about this as well.  Take care!

Note: a lot of the credit goes to David Tse who gave me these details.