I'm trying to add dynamically elements to a root using LINQ, it was working before. But it returns "Object reference not set to an instance of an object.". It only works creating the new XElement instance manually.
try
{
XDocument xdoc = XDocument.Load(_documentName);
XElement _newElements = new XElement(_rowName);
foreach(string s in _commaSeparatedNameValues)
{
_newElements.Add(new XElement( s.Split(',')[0], s.Split(',')[1]));
}
xdoc.Element(_rowName).Add(_newElements);
xdoc.Save(_documentName);
}
catch(Exception ex)
{
string s = ex.Message;
}