Kman Kman - 3 months ago 61
C# Question

Word VSTO CustomXMLNode.SelectSingleNode fails after Office upgrade

A word vsto addin fails with exception on calling CustomXMLNode.SelectSingleNode.

The addin runs fine with word 2007 - 2013, but on version 2016 it fails with Reference to undeclared namespace prefix: 'ns0'.

visual studio screenshot

I've made a workaround navigating the XML without the use of xpath and these methods, but still need to figure out how to solve this issue.

var xPathExpression = String.Format(

The resulting xPathExpression is


The xml looks like this:

<MyXmlTest xmlns="">
<Ribbon visible="true">
<Group name="xmlProperties">Document Properties</Group>
<Group name="xmlActions">Other Properties</Group>
<Properties ribbonLabel="Hello World Menu">
<Property name="helloWorld">
<RibbonButton groupName="xmlActions">
<DisplayText>Hello World</DisplayText>
<Tooltip>Some text goes here.</Tooltip>
<Property name="title">
<RibbonButton groupName="xmlProperties">
<DisplayText>Hello World Text</DisplayText>
<Tooltip>Insert Hello World in Document</Tooltip>


Usually, to execute XPath containing namespace prefix you need to pass along namespace manager containing the prefix-URI mapping. Since this option isn't available in your case, as a workaround, you can try to ignore namespaces by using local-name() :