[NullReferenceException: Object reference not set to an instance of an object.]
umbraco.NodeFactory.Node.initialize() +172
umbraco.NodeFactory.Node..ctor(XmlNode NodeXmlNode) +179
umbraco.NodeFactory.Node.GetNodeByXpath(String xpath) +168
In the XPath expression you need to use the document type's alias (i.e. "Employee") - so if it's <Employee> in the XML, it should be Employee in the expression, i.e.:
The error you get is because the code that deals with an umbraco Node, and all of the working XPath expressions return a node - the ones throwing an error, selects a property instead. I didn't catch that your code was using a node (the "nodeEmail" name threw me off, I guess :-). Sebastian's XPath selects the <Employee> node that has an <email> equal to 'xxx', whereas mine selected the actual<email> element. Subtle difference - but if your C# code expects a Node, the error message makes perfect sense.
GetNodeByXpath throws NullReferenceException
I'm working on a project using Umbraco 6 and WebForms.
In Content, there are Employees. So umbraco.config contains these lines:
In C#, how do I get the Employee node having email=xxx? I tried this:
and it throws this exception:
Hi Hardi,
In the XPath expression you need to use the document type's alias (i.e. "Employee") - so if it's
<Employee>
in the XML, it should beEmployee
in the expression, i.e.:/Chriztian
Oh I'm sorry I cut and pasted the wrong thing. I can't edit it anymore.
It was already Employee. But it throws a NullReferenceException.
These lines are fine:
But this throws NullReferenceException
Try this:
It works! Thank you Sebastian!
I still don't understand why the other queries were throwing the exception, even though they were fine when tested on XPath testers. But thanks!
Hi Hardi,
The error you get is because the code that deals with an umbraco Node, and all of the working XPath expressions return a node - the ones throwing an error, selects a property instead. I didn't catch that your code was using a node (the "nodeEmail" name threw me off, I guess :-). Sebastian's XPath selects the
<Employee>
node that has an<email>
equal to 'xxx', whereas mine selected the actual<email>
element. Subtle difference - but if your C# code expects a Node, the error message makes perfect sense.Does that help understanding?
/Chriztian
Ah of course! I was concentrating too much on the XML I forgot about the Node itself! Thank you Chriztian :)
is working on a reply...