- Home /
Getting NullReferenceException: Object reference not set to an instance of an object when using Linq reading an xml file.
Hi, I am getting this error even though I am getting value .This is my code:
public class Assessments : MonoBehaviour {
public string dataName;
void Start () {
XElement xDoc = XElement.Load(Application.dataPath + "/XmlDocs/"+dataName+".xml");
IEnumerable<XElement> AllData = xDoc.Elements();
// Read the entire XML
foreach (var mentalApplication in AllData)
{
string a = mentalApplication.Element("ScoutUser").Value;
print(a);
}
}
}
Thanks.
ReEdit your title: (There is a character missing)
Getting NullReferenceException: Object reference not set to an instance of an object when using Linq reading an xml file.
Answer by povilas · Apr 07, 2014 at 04:40 PM
It's likely that one of the children of the root element does not have "ScoutUser" child. Could you paste full error message and the test XML file, so that it's possible to investigate the real reason of the exception?
Your answer
Follow this Question
Related Questions
Problems with Loading a XML File for a TileMap using XMLTextReader 1 Answer
A node in a childnode? 1 Answer
Linq List to Gui 0 Answers
LINQ, XML, putting XML nodes into an array 2 Answers
Can not reference System.Xml.Linq 3 Answers