Hi I get an error on the line commented in the below code object reference not set to an instance of an object is there a way to fix it?
private void button20_Click(object sender, EventArgs e)
{
string blabla1 = string.Format("http://localhost:8000/Service/AuthenticateUser/{0}/{1}", textBox30.Text, textBox31.Text);
XDocument xDoc = XDocument.Load(blabla1);
xDoc.Element("StudentID").Value.ToList(); // object reference not set to an instance of an object?
dataGridView12.DataSource = xDoc;
}
When
xDoc.Element("StudentID")is not found, calling.Valuewill give that exception.You probably want
But that assumes the XML does not use namespaces.
Edit: