I have an odd problem with .net framework 4 appending anything to an xml document.
I have a small (35k) xml file that I am trying to add comments to. It used to work fine, but now when I try to add anything to the file, it gets stuck when I append anything to the xml document. I can edit the comments with no problem.
The Call Stack indicates that it may have something to do with the XmlElementListListener.OnListChanged. I'm not sure why, because I'm not using any xml events.
Thanks for your assistance.
mscorlib.dll!System.MulticastDelegate.RemoveImpl(System.Delegate value) + 0xaa bytes
System.Xml.dll!System.Xml.XmlElementListListener.OnListChanged(object sender, System.Xml.XmlNodeChangedEventArgs args) + 0xe6 bytes
System.Xml.dll!System.Xml.XmlNode.AfterEvent(System.Xml.XmlNodeChangedEventArgs args) + 0x27 bytes
System.Xml.dll!System.Xml.XmlNamedNodeMap.AddNode(System.Xml.XmlNode node) + 0x104 bytes
System.Xml.dll!System.Xml.XmlAttributeCollection.AddNode(System.Xml.XmlNode node) + 0x42 bytes
System.Xml.dll!System.Xml.XmlAttributeCollection.Append(System.Xml.XmlAttribute node) + 0x96 bytes
> cmsoClashReports.dll!Camansol.Camansys.CMSGlobal.ClashReports.ClashComments.Add(Camansol.Camansys.CMSGlobal.ClashReports.Status _resultStatus) Line 322 + 0x34 bytes C#
This is the xml snippet:
<exchange xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" units="m" filename="" filepath="">
<batchtest name="Report" internal_name="Report" units="m">
<clashtests>
<!--
<summmary />
<clashreults>
<clashresult name="Clash4" guid="0091a62c-fb5e-4aa7-82eb-0c5814d58bdc" href="Piping_files\cd000001.jpg" status="reviewed" distance="-0.004">
<description>Hard</description>
<resultstatus>Reviewed</resultstatus>
<clashpoint>
<pos3f x="25.960" y="19.206" z="4.018" />
</clashpoint>
<createddate>
<date year="2016" month="5" day="2" hour="22" minute="45" second="52" />
</createddate>
<clashobjects />
<comments> <!--
<comment id="10000" status="new">
<body>Replace Flanges</body>
<user>usename</user>
<createddate>
<date year="2016" month="5" day="9" hour="15" minute="0" second="26" />
</createddate>
</comment>
</comments>
</clashresult>
</clashresults>
</clashtests>
</batchtest>
</exchange>
This is the code:
public void Add(Status _resultStatus)
{
int iNextID = 10000 + this.GetNextID; ;
DateTime _dtComment = DateTime.Now;
XmlDocument _xdClashReport = this.xmlClashComments.OwnerDocument;
XmlElement _nodNewComment = _xdClashReport.CreateElement("comment");
XmlElement _nodNewCommentUser = _xdClashReport.CreateElement("user");
XmlElement _nodNewCommentBody = _xdClashReport.CreateElement("body");
XmlElement _nodNewCommentCreatedDate = _xdClashReport.CreateElement("createddate");
XmlElement _nodNewCommentDate = _xdClashReport.CreateElement("date");
XmlAttribute _xatrNewCommentID = _xdClashReport.CreateAttribute("id");
XmlAttribute _xatrNewCommentStatus = _xdClashReport.CreateAttribute("status");
_nodNewComment.Attributes.Append(_xatrNewCommentID);
_nodNewComment.Attributes.Append(_xatrNewCommentStatus);
_nodNewComment.SetAttribute("id", iNextID.ToString());
_nodNewComment.SetAttribute("status", _resultStatus.ToString().ToLower());
XmlAttribute _xatrNewCommentDateYear = _xdClashReport.CreateAttribute("year");
XmlAttribute _xatrNewCommentDateMonth = _xdClashReport.CreateAttribute("month");
XmlAttribute _xatrNewCommentDateDay = _xdClashReport.CreateAttribute("day");
XmlAttribute _xatrNewCommentDateHour = _xdClashReport.CreateAttribute("hour");
XmlAttribute _xatrNewCommentDateMinute = _xdClashReport.CreateAttribute("minute");
XmlAttribute _xatrNewCommentDateSecond = _xdClashReport.CreateAttribute("second");
_nodNewCommentDate.Attributes.Append(_xatrNewCommentDateYear);
_nodNewCommentDate.Attributes.Append(_xatrNewCommentDateMonth);
_nodNewCommentDate.Attributes.Append(_xatrNewCommentDateDay);
_nodNewCommentDate.Attributes.Append(_xatrNewCommentDateMonth);
_nodNewCommentDate.Attributes.Append(_xatrNewCommentDateHour);
_nodNewCommentDate.Attributes.Append(_xatrNewCommentDateMonth);
_nodNewCommentDate.Attributes.Append(_xatrNewCommentDateMinute);
_nodNewCommentDate.SetAttribute("year", _dtComment.Year.ToString());
_nodNewCommentDate.SetAttribute("month", _dtComment.Month.ToString());
_nodNewCommentDate.SetAttribute("day", _dtComment.Day.ToString());
_nodNewCommentDate.SetAttribute("hour", _dtComment.Hour.ToString());
_nodNewCommentDate.SetAttribute("minute", _dtComment.Minute.ToString());
_nodNewCommentDate.SetAttribute("second", _dtComment.Second.ToString());
_nodNewCommentUser.InnerText = Environment.UserName;
_nodNewCommentBody.InnerText = "New Comments";
_nodNewCommentCreatedDate.AppendChild(_nodNewCommentDate);
_nodNewComment.AppendChild(_nodNewCommentBody);
_nodNewComment.AppendChild(_nodNewCommentUser);
_nodNewComment.AppendChild(_nodNewCommentCreatedDate);
this.xmlClashComments.AppendChild(_nodNewComment);
ClashComment _newClashComment = new ClashComment();
_newClashComment.xmlClashComment = _nodNewComment;
this.List.Add(_newClashComment);
if (OnClashCommentAdded != null)
{
OnClashCommentAdded(this, new ClashCommentsEventArgs());
}
}
What I have tried:
Tried creating a new project
upgrading to .net framework 4.5
reverting to previous version of my code