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

  • SEARCH
  • Home
  • 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 8392583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:33:04+00:00 2026-06-09T19:33:04+00:00

I have an issue whilst streaming to a file, I’m sure there is a

  • 0

I have an issue whilst streaming to a file, I’m sure there is a simple solution but I’m struggling to find it! What I’m attempting to do is very straightforward, I’m getting the contents of a class and serializing them into XML and streaming them to a file. The code I’m using is:

 ObservableCollection<RackItemViewModel> rackVMs = ProjectTree.GetTreeData();

 XmlSerializer serializer = new XmlSerializer(typeof(RackItem));
 using (TextWriter tw = new StreamWriter(filename, false))
 {
     foreach (RackItemViewModel VM in rackVMs)
         serializer.Serialize(tw, VM.RackItem);
 }

ProjectTree.GetTreeData() just returns the data to be serialized. If I run the program and save the data it all works as expected, the data is saved and can be read back with Deserialize. The problem I’m having is when I perform more than one save. If I save one set of data to one file and then another set of data to another file, the first file is correct but the second file is a concatenation of the first file and the second! It seems that either the stream or the XMLSerializer are not releasing their contents between saves. I’ve tried using writefile instead of Stream and I still get the same issue, I’ve also tried flushing and closing the stream but this has no effect. Needless to say if I close and restart the application between saves it all works fine.
Could anyone tell me what I’m doing wrong please?

  • 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-09T19:33:05+00:00Added an answer on June 9, 2026 at 7:33 pm

    I thought I’d tidy up this thread as I’ve managed to solve the problem. It turns out that it was nothing to do with the serializing or streaming of the data. The data buffer being written wasn’t fully releasing the data between writes. I was checking the View Model object which was OK but the object being written (RackItem), wasn’t following suite. Silly error on my part. Thanks for the suggestions.

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

Sidebar

Related Questions

I have a very weird issue whilst initializing a struct with GCC 4.5.3 on
I have an issue which I could not find answer for across the web.
I have an issue while getting the file name with out extension from a
I'm having a simple issue where my C executable is crashing after attempting to
I have an issue with a 3rd party DLL, which is NOT thread-safe, but
Whilst creating an inline ANTLR Tree Grammar interpreter I have come across an issue
I have not made any core changes, but this morning whilst doing some W3
I have issue with: <form:checkboxes path=roles cssClass=checkbox items=${roleSelections} /> If previous line is used
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
We are new to ROR, We have issue in creating Login/Logout process in ROR

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.