Try this:
var doc1 = XDocument.Load(@"C:\any.xml", LoadOptions.SetLineInfo);
var doc2 = new XDocument(doc1);
doc2 no longer has any line number information. Digging in with Reflector, I can see that when the nodes are cloned from doc1 to doc2 this does not preserve the annotations on the XObject base type, which includes the line number information accessible via IXmlLineInfo
. Nor does it retain the BaseUri, which I also need.
Any ideas how I can clone the document while preserving line numbers? I found this but it doesn't preserve BaseUri and is a bit of a hack.