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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:17:46+00:00 2026-05-25T17:17:46+00:00

really stuck, any help and/or comments would be greatly appreciated! I’ve written a database

  • 0

really stuck, any help and/or comments would be greatly appreciated!

I’ve written a database program that needs to be able to load contents from a file into a list. So basically i’m trying to use serialization and deserialization for this. The area where the error occurs is in bold and is italicized:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace ConsoleApplication1
{
    class TheFile
    {
        //Version 1 serialiser, instance specific, so a bit of a pain

        public void SerializeObject(string filename, TheDocument document)
        {
            Stream stream = File.Open(filename, FileMode.Create);
            BinaryFormatter bFormatter = new BinaryFormatter();
            bFormatter.Serialize(stream, document);
            stream.Close();
        }
        public TheDocument DeSerializeObject(string filename)
        {
            TheDocument document;
            Stream stream = File.Open(filename, FileMode.Open);
            BinaryFormatter bFormatter = new BinaryFormatter();
            ***document = (TheDocument)bFormatter.Deserialize(stream);***
            stream.Close();
            return document;
        }
    }
}

The error which i receive is as follows: The input stream is not a valid binary format. The starting contents (in bytes) are: 31-37-2F-30-39-2F-32-30-31-31-20-31-31-3A-30-36-3A …

  • 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-05-25T17:17:47+00:00Added an answer on May 25, 2026 at 5:17 pm

    I have seen this reported somewhere else recently, and I was unable to find an explanation there either. The code as presented looks like it should be fine (although it would benefit greatly from a few using statements, but they won’t break the success case since you are calling .Close()).

    However! I would also warn that IMO BinaryFormatter is not a good choice for storage in a database, since that suggests it is desirable to read it back in the future. The fact that BinaryFormatter is type-dependent makes it very very brittle as you version your application. Any of: creating a new app-version, renaming/adding/removing a field, changing a property to an automatically implemented property, changing .NET version, changing platform, … could make your data either unreadable, or readable only by adding a lot of custom binder code.

    I strongly suggest that you consider using a contract-based serializer instead of BinaryFormatter; any of: DataContractSerializer (but not NetDataContractSerializer), XmlSerializer, JavascriptSerializer, JSON.Net. If you want binary for size and performance, then protocol buffers (with several C# implementations, including protobuf-net) is designed (by Google) to be version tolerant, small, and fast. Since that list is also cross-platform, it also means your data is safe if, say, you switch platform to Java, Mono, WinRT (the new windows 8 subsystem), PHP, or anything else. BinaryFormatter will not work on any of those.

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

Sidebar

Related Questions

I am kind of really stuck with this problem. Any help will great. I
Hey, I'm really stuck with my project here... I need to know when any
We are stuck with Java2SE v1.4 till the end of 2010. That's really nasty,
I am brand new to Raphael and am really stuck, I would like to
I hope someone can offer any help!! I have web page that initiates a
I am fairly new to WPF, and am a bit stuck, so any help
I was hoping for some help on this as I'm really stuck after trying
I'm really stuck with a problem I'm hoping someone can help me with. I'm
Really stuck on trying to write code to unzip a file or directory on
I'm really stuck on why the following code block 1 result in output 1

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.