Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8253175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:47:15+00:00 2026-06-08T00:47:15+00:00

I have a really strange problem with XMLReader/XMLTextReader classes. I have a simple file

  • 0

I have a really strange problem with XMLReader/XMLTextReader classes.

I have a simple file load:

public void First()
{
    XmlTextReader reader = new XmlTextReader(@"C:\MyXMLFile.xml");
    XmlReader readerToSerialize;
    XmlReader readerToLoad;
    DuplicateReaders(reader, out readerToSerialize, out readerToLoad);
    XmlSerializer serializer = new XmlSerializer(typeof(XMLTree));
    XmlFeed = (XMLDescriptor)serializer.Deserialize(readerToSerialize);
    xmlDoc.Load(readerToLoad);
}
protected void DuplicateReaders(XmlTextReader xmlReader, out XmlReader cloneOne, out readerToLoad)
{
    XmlDocument _XmlDocument = new XmlDocument();
    MemoryStream _Stream = new MemoryStream();
    _XmlDocument.Load((XmlTextReader)xmlReader);
    _XmlDocument.Save(_Stream);
    _Stream.Position = 0L;
    cloneOne = XmlReader.Create(_Stream);
    _Stream.Position = 0L;
    cloneTwo = XmlReader.Create(_Stream);
}

The problem is that only one of the cloned elements read the whole file successully, the next one (xmlDoc.Load) fails always at the same place (Line 91, Character 37 with this xml file). If I directly assign to xmlDoc (i.e. clone the original element only once and asign it directly from the function):

public void First()
{
    XmlTextReader reader = new XmlTextReader(@"C:\MyXMLFile.xml");
    XmlReader readerToSerialize;
    DuplicateReaders(reader, out readerToSerialize);
    XmlSerializer serializer = new XmlSerializer(typeof(XMLTree));
    XmlFeed = (XMLDescriptor)serializer.Deserialize(readerToSerialize);
}
protected void DuplicateReaders(XmlTextReader xmlReader, out XmlReader cloneOne)
{
    XmlDocument _XmlDocument = new XmlDocument();
    MemoryStream _Stream = new MemoryStream();
    _XmlDocument.Load((XmlTextReader)xmlReader);
    _XmlDocument.Save(_Stream);
    _Stream.Position = 0L;
    cloneOne = XmlReader.Create(_Stream);
    _Stream.Position = 0L;
    this.xmlDoc.Load(_Stream);
}

I still get the same error 91/37 (Unexpected EOF), but this time in the Serializer.

My initial problem was that if I use xmlDoc.Load(reader) the reader instance get destroyed and I can’t serialize it later on. I found the Duplicate function on the MSDN forums, but it’s still a no go. What I want to achieve is quite simple:

Use only one reader and get one XmlDocument and one Serialized Class. How hard can it be?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T00:47:17+00:00Added an answer on June 8, 2026 at 12:47 am

    Found much easier solution, instead of cloning the two readers, i just use create a second one from XmlDoc and use it to deserialize.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've come across a really strange problem. I have written a simple Deck class
I have a really strange problem with WPF. A simple window with a button
Hi everyone I have a really strange problem. I create a new subclass of
We have a really strange problem in xpages regarding dates, the Notesdocument we have
I have a really strange problem with SQL Server 2008. We have an e-commerce
I have a really strange problem and I'm completely puzzled. I have a piece
I'm having a really strange problem. I have 2 virtual machines running ubuntu 11.4
I am having some strange problem and its really frustating me. I have a
We have a strange problem. I added a couple of new schema's and orchestrations
I have a really strange problem. I'm using jQuery 1.7.1 and UI 1.8.17 for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.