OneNote Interop API targets wrong window instance when multiple

stemarcoh 26 Reputation points
2024-11-23T14:05:09.3+00:00

C# with .NET Framework 4.8, Microsoft® OneNote® 2021 MSO (Version 2410 Build 16.0.18129.20100) 64-bit

Open up two OneNote windows viewing the same page. From the second window, invoke an add-in command that uses the managed Interop API.

Any queries or updates made by the API will target the first OneNote window instance, even while the second window instance is active and has focus.

However, if the content of the page is manually modified from the second [active] window instance, then and only then will the API call target and update the page in the second window.

Expectation is that the updated page content will be visible immediately in the active OneNote window instance.

Microsoft 365 and Office | Development | Other
Microsoft 365 and Office | OneNote | For business | Windows
Developer technologies | C#
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Jason Chapman 41 Reputation points
    2024-11-24T13:27:07.9933333+00:00

    A great example of this is when your add-in wants to know "what is the selected text" in the focused, second instance, as the XML request will always give the results from the 1st instance. If you close the first instance or move to another page in the 1st instance, the query will give the correct information.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.