I'm completely stumped, I've used very similar code before and it worked perfectly, the XML in this was written by a separate method in this program and I checked it against it and it looked fine
That's the code for parsing the XML file
UserType CurrentUser = new UserType();
XDocument UserDoc = XDocument.Load(Path2UserFile);
XElement UserRoot = UserDoc.Element("User");
CurrentUser.User_ID = int.Parse(UserDoc.Element("User_ID").Value);
CurrentUser.Full_Name = UserDoc.Element("Full_Name").Value;
CurrentUser.Gender = UserDoc.Element("Gender").Value;
CurrentUser.BirthDate = DateTime.Parse(UserDoc.Element("Birthdate").Value);
CurrentUser.PersonType = int.Parse(UserDoc.Element("PersonType").Value);
CurrentUser.Username = UserDoc.Element("Username").Value;
CurrentUser.Password = UserDoc.Element("Password").Value;
CurrentUser.Email_Address = UserDoc.Element("Email_Address").Value;
The Path2UserFile points to the correct file as well, and I had it write out the full path.
It has a NullReferenceException whenever it tries to parse the contents of any of the elements
The XML File follows this format
<User>
<User_ID>11</User_ID>
<Full_Name>Sample User</Full_Name>
<Gender>Male</Gender>
<BirthDate>12/12/2010 12:00:00 AM</BirthDate>
<PersonType>2</PersonType>
<Username>Sample User</Username>
<Password>sample123</Password>
<Email_adddress>[email protected]</Email_adddress>
</User>
The UserType class looks like this
class UserType
{
public int User_ID = 0;
public string Full_Name = string.Empty;
public string Gender = string.Empty;
public DateTime BirthDate;
public int PersonType = 0;
public string Username = string.Empty;
public string Password = string.Empty;
public string Email_Address = string.Empty;
}
I have no clue as to what's wrong, any help would be very much appreciated