An easier way to troubleshoot addins for OneNote


 

I got fed up with attaching a debugger to addins in OneNote.  The typical process (as suggested by Dan Escapa) is to have your addin open a dialog when it starts, then attach to the running process while the dialog is onscreen.  That got annoying rather quickly and I started to look for an easier way to attach to a running powertoy.  It turns out System.Diagnostics has just the method I need.


 


The easier way to attach a debugger is to call


System.Diagnostics.Debugger.Launch();


This will automatically attach your default debugger to the running process.  If you want, you can surround that line with DEBUG conditional statements like this:


 


#if DEBUG


System.Diagnostics.Debugger.Launch();


#endif


 


Now if you are using VS to create a debug build, the debugger will get attached.  Ship builds will not include these lines.


 


After getting the debugger attached, I was still forced to uninstall the previous build of my addin and run the install to get the new bits into place.  The last tip is making it easier to spoof the install for new builds so you don’t have to spend time uninstalling, reinstalling or even building the setup project each time.


 


Build and install the debug app once.


Go back into Visual Studio and redirect the debug output to the folder in which you installed your app.


(optional: you can turn off building the setup project each time now)


Now when you rebuild or recompile, the old dll gets overwritten by the new, and you do not have to uninstall/reinstall for each new compile.  This works great since the GUID doesn’t change once the project is created.


When you are done, be sure to rebuild the setup project.


 


These are just a couple of tweaks I discovered recently.  Nothing earth shattering – just simple time savers.


 


Questions, comments, criticisms and concerns always welcome,


John

Comments (6)

  1. Anirudh says:

    This is a great tip and would save a lot of developing trouble. However when I use the above code I get a "launch for user" JIT error in dllhost.exe. Visual Studio then opens but doesn’t load anything. The addin continues to work though.

    Also, each time I rebuild by dll and setup project file, it still installs the older version(even though I uninstall it before running the new build setup). I need to create a new setup project each time I make any changes to my dll. I tried incrementing the version of the setup, dll assembly, manually copying the new dll in the installation folder, the GAC folder but OneNote still runs the previous version of the DLL. The only way I manage to update is by creating a new setup project and installing it again.

    How can I make your suggestion of redirecting my dll compiled output to the installation folder work?

    Thanks,

    Ani

  2. JohnGuin says:

    Good catch.  OneNote remains in memory for 15 minutes after loading addins due to a COM limitation.  I never had hit this since I was taking > 15 minutes to make changes, recompile, etc…  

    Two things to do:

    1. Let ON exit normally

    2. Kill the process.

    Sorry for the confusion,

    John

  3. I wanted to pass on a story that I read in my RSS reader that John blogged about a couple weeks ago:

  4. I wanted to pass on a story that I read in my RSS reader that John blogged about a couple weeks ago:

  5. I received a few questions about my tip concerning a quicker way to troubleshoot addins during development.

  6. I received a few questions about my tip concerning a quicker way to troubleshoot addins during development