private XmlException ParseInternal(string text) { stream.SetText(text); if (reader == null) { reader = new XmlTextReader(stream); } try { while (!ReachedEnd()) { reader.Read(); } // No errors. Reset the text reader for next time. reader.ResetState(); return(null); } catch (XmlException ex) { // The reader is in a bad state and ResetState isn't going to help (because it has already // consumed bad text from the underlying stream and that can't be undone). // So, dispose of it and recreate a new one next time we get called. reader.Dispose(); reader = null; return(ex); } }