I am trying to write something to xml file. I have a function:
bool WriteValueTOXML(string pstrValueToRead, string pstrValueToWrite)
{
try
{
XmlTextReader reader = new XmlTextReader("config.ini");
XmlDocument doc = new XmlDocument();
doc.Load(reader);
reader.Close();
XmlNode oldNode;
XmlElement root = doc.DocumentElement;
oldNode = root.SelectSingleNode(@"/settings/" + pstrValueToRead);
oldNode.InnerText = pstrValueToWrite;
doc.Save("config.ini");
return true;
}
catch (NullReferenceException e)
{
MessageBox.Show(e.Message);
return false;
}
}
When I am trying to set InnerText in oldNode (oldNode.InnerText = pstrValueToWrite;) the NullReferenceException is thrown with message "Object reference not set to an instance of an object".
File that I am trying to write to is here:config.ini