I wanted to highlight some issues developers might have if they try and program against the OneNote 2010 API with Visual Studio 2010.
Make sure to reference the COM API and not the .Net API
First of all there is an issue with the interop assembly that shipped with Visual Studio 2010, it is out of date because we had to make a change to the API after the VS team took their final drop. It is sad that this happened and working across teams but it just means that you should NOT reference the OneNote 14.0 object from the .Net tab and instead reference it from the COM tab:
Make sure to turn off ‘Embed Interop Types’
There is a new feature in Visual Studio 2010 where most PIAs are no longer embedded in the application by default, this has been called the NOPIA. Misha Shneerson has some details about this on his blog here: Better eventing support in CLR 4.0 using NOPIA support.
However OneNote 2010’s typelib is not compatible with this feature and by default after you have added a reference to OneNote 2010 typelib you will see this error:
Error 1 ‘Microsoft.Office.Interop.OneNote.Application’ does not contain a definition for ‘GetHierarchy’ and no extension method ‘GetHierarchy’ accepting a first argument of type ‘Microsoft.Office.Interop.OneNote.Application’ could be found (are you missing a using directive or an assembly reference?) C:\ConsoleApplication1\ConsoleApplication1\Program.cs 15 19 ConsoleApplication1
This was from the ‘GetHierarchy’ method but you would see it with any method you call into OneNote. This is due to the new NOPIA option and you would need to turn if off to get things working again.
Turning off NOPIA/embed interop types for OneNote 2010:
- Find the reference to Microsoft.Office.Interop.OneNote on the Solution Explorer
- Click on it and view the properties down below
- Find the value Embed Intero Types and change it from True to False
- Recompile and you should be all set
Now you should be all set.
I will blog more about other OneNote 2010 API/extensibility changes but in the meantime I wanted to pass on some of these details to make sure you weren’t blocked. Visual Studio 2008 & 2005 shouldn’t have this problem because it was a new feature in VS2010 and .Net 4.