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.

Comments (6)

  1. Blair says:

    You can also add this code to your object constructor in order to launch the debugger from inside of your addin:


    #if DEBUG




    This will either launch a new debugger or attach to an already existing one (also the code gets compiled away under Release mode removing all chances of the debugger launching).


  2. Chris says:

    This also works, if (!Debugger.IsAttached) Debugger.Break();

  3. Kevin Damen says:


    I am having a problem, the button appears in the tool bar in One note correctly, but as soon as it is clicked on it becomes disabled.

    the popup never appears.

    Kevin Damen

  4. Kevin – This means that the toolbar addin isn’t registered correctly.  Have you read my documentation here:

    I have also seen problems if you are using Vista and have UAC/LUA disabled.  You can always turn on the debugging and see what error OneNote sees when trying to call the COM methods.

  5. Simon says:

    I have the same problem as Kevin. I did put a message box in addin class’ constructor and it appears so OneNote does find the addin class. However after I do anythign – for example close the message box – my addin button is disabled and no events go through.

    I have succesfully used DevPal addin, so I know I have a "home made" problem somewhere but I just am not able to locate it. Any ideas?

  6. John Rea-Hedrick says:

    I had the same issue trying to use the Search and Replace add-in.

    I went back into my Office installtion setup and noticed that .NET Programmability Support was not installed.  Just for good measure I also installed Microsoft Forms 2.0 .NET Programmability Support.

    Worked like a charm!

    I launched OneNote and clicked the button; the form window popped right up.  I didn’t even have to reboot or go dig out my Office 2007 installation media!

Skip to main content