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 8447065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:05:37+00:00 2026-06-10T10:05:37+00:00

I was reading a binary file and while waiting for something to happen, I

  • 0

I was reading a binary file and while waiting for something to happen, I noticed that the program wasn’t doing anything.

It seemed to be stuck at a certain point in execution. I added in some print statements to console, and can see that it gets to a certain point…but then doesn’t seem to want to continue. This is the first couple lines of code:

private BinaryReader inFile;
public void Parser(string path)
{
    byte[] newBytes;
    newBytes =  File.ReadAllBytes(path);

    using (MemoryStream ms = new MemoryStream())
    {
        ms.Write(newBytes, 0, newBytes.Length);
        inFile = new BinaryReader(ms);
        inFile.BaseStream.Seek(0, SeekOrigin.Begin);
    }
}

public void ParseFile()
{
  Console.WriteLine("parsing");
  Console.WriteLine("get size to read"); // prints this out
  int sizeToRead = inFile.ReadInt32();
  Console.WriteLine("Size: {0}", sizeToRead); // doesn't print this out
  Console.WriteLine("Done"); // end file processing
}

When I comment out the read, it works fine. I dumped the contents of inFile into a new file and it was the same as the original file, so it should be a valid stream.

I am not sure how to continue debugging this issue. Anyone ran into similar issues?

EDIT: Sorry, I was posting bits and pieces of different methods. Here’s the whole methods

  • 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-10T10:05:38+00:00Added an answer on June 10, 2026 at 10:05 am

    Once you leave the using block, the MemoryStream is disposed, making your BinaryReader invalid as well. Throwing away the memory stream is pulling the rug out from under your binary reader. Move all of your related reading code into a using block, if you can, and wrap your BinaryReader in one as well.

    using (var ms = new MemoryStream(File.ReadAllBytes(path)))
    using (var inFile = new BinaryReader(ms))
    {
        inFile.ReadInt32();
    }
    

    You can read directly from the file as well, unless you have a reason to read it all in and feed it through a MemoryStream.

    If the way your code is laid out keeps you from using using, then you can keep track of the MemoryStream and BinaryReader objects and implement IDisposable. Then call Dispose` on them later to clean up.

    The garbage collector will clean up eventually if you don’t do this, but calling Dispose on anything that is IDisposable is good habit to get into. If you don’t, you may run into issues with open file handles or GDI objects sitting around in the finalizer queue waiting to be disposed.

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

Sidebar

Related Questions

I have a C++ program that will read in data from a binary file
Hi everyone i have an issue while reading binary data from a binary file
Python 3 really complicated the whole file reading process, when you have a binary
I am having following issue with reading binary file in C. I have read
I'm reading from a binary file and want to convert the bytes to US
i am reading in a binary file via the usual c++/STL/iostream syntax. i am
Using Windows So I'm reading from a binary file a list of unsigned int
I'm reading from a binary data file which is written by invoking the following
I'm tasked with reading a poorly formatted binary file and taking in the variables.
Currently, I have been reading lists of data from a binary data file programmatically

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.