I wrote this simple linq-to-xml query and it seems that null exception could not be avoided using the the linq syntax. Am I using it wrong? What should be the right (and short) Linq2Xml syntax?
The linq2Xml query
var userData =
queryUserResponseData.Elements("user")
.Single(u => u.Element("username").Value == userName);
The XML
<data>
<user>
<username>User1</username>
<userid>123</userid>
</user>
<user>
<username>User2</username>
<userid>456</userid>
</user>
<user>
<userid>999</userid>
</user>
</data>