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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:08:36+00:00 2026-05-15T11:08:36+00:00

Has anyone experienced issues with Serialization on Windows 7 64-bit under Visual Studio 2008?

  • 0

Has anyone experienced issues with Serialization on Windows 7 64-bit under Visual Studio 2008?

I can Serialize my object before exiting with no errors, but when I open the object back up, my changed data is not there.

The only difference I know of is that I am on Windows 7 64-bit (previous was Win XP 32-bit).

My code below works fine, and none of the exceptions are triggered. Still, if I change the value of my object data and Serialize it, it will not pull back up when I go back and deserialize that same data.

static void Settings(object objModel, StoreOption value) {
  Model obj = objModel as Model;
  if (obj == null) return;
  if (!Directory.Exists(ExePath)) {
    Directory.CreateDirectory(ExePath);
  }
  string cfgFile = Path.Combine(ExePath, _CFG_FILE);
  bool ok = File.Exists(cfgFile);
  switch (value) {
    case StoreOption.Load:
      if (ok) {
        try {
          using (Stream stream = File.Open(cfgFile, FileMode.Open, FileAccess.Read)) {
            IFormatter formatter = new BinaryFormatter();
            obj = formatter.Deserialize(stream) as Model;
          }
        } catch (SerializationException err) {
          Console.WriteLine(err);
          obj = null;
        }
      }
      break;
    case StoreOption.Save:
      if (ok) {
        try {
          File.Delete(cfgFile);
        } catch (Exception err) {
          Console.WriteLine(err);
        }
      }
      if (obj == null) {
        obj = new Model();
      }
      using (Stream stream = File.Open(cfgFile, FileMode.Create, FileAccess.Write)) {
        try {
          IFormatter formatter = new BinaryFormatter();
          formatter.Serialize(stream, obj);
        } catch (SerializationException err) {
          Console.WriteLine(err);
        }
      }
      break;
  }
}

Edit (06/25/2010 @ 9 AM CST): Using jdehaan‘s suggestion, I split up the static void Settings(object objModel, StoreOption value); method into the following two methods.

This routine still fails to recall changes I make to the object. I can modify the data sent to Serialize and there are no errors. Is the data correctly serialized in my file? I don’t know because I don’t know how to interpret the data in a text viewer like Notepad. However, whenever I recall the saved data with the Deserialize method, the data returned is NOT what I saved!

static Model Deserialize() {
  Model obj;
  if (!Directory.Exists(ExePath)) {
    Directory.CreateDirectory(ExePath);
  }
  string cfgFile = Path.Combine(ExePath, _CFG_FILE);
  bool ok = File.Exists(cfgFile);
  if (ok) {
    try {
      using (Stream stream = File.Open(cfgFile, FileMode.Open, FileAccess.Read)) {
        IFormatter formatter = new BinaryFormatter();
        obj = formatter.Deserialize(stream) as Model;
      }
    } catch (SerializationException err) {
      Console.WriteLine(err);
      obj = null;
    }
  } else {
    obj = null;
  }
  return obj;
}


static void Serialize(Model obj) {
  if (obj == null) return;
  if (!Directory.Exists(ExePath)) {
    Directory.CreateDirectory(ExePath);
  }
  string cfgFile = Path.Combine(ExePath, _CFG_FILE);
  bool ok = File.Exists(cfgFile);
  if (ok) {
    try {
      File.Delete(cfgFile);
    } catch (Exception err) {
      Console.WriteLine(err);
    }
  }
  if (obj == null) {
    obj = new Model();
  }
  using (Stream stream = File.Open(cfgFile, FileMode.Create, FileAccess.Write)) {
    try {
      IFormatter formatter = new BinaryFormatter();
      formatter.Serialize(stream, obj);
    } catch (SerializationException err) {
      Console.WriteLine(err);
    }
  }
}
  • 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-15T11:08:37+00:00Added an answer on May 15, 2026 at 11:08 am

    Pass your objModel by reference

    static void Settings(ref object objModel, StoreOption value) { ... }
    

    objModelwill not be modified on reading otherwise. See C# Parameters for some more information. Alternatively write two separate functions for reading and writing, the first returning an objModel the second having one as first parameter.

    ADDED:

    If you are using a NON Express Visual Studio, activate first chance exceptions, I think there must be something with the access rights to the file. Is the file timestamp newer`If not the file was not actually saved.

    I would enclose following code in a try/catch block also:

    try {
        using (Stream stream = File.Open(cfgFile, FileMode.Create, FileAccess.Write)) {
            try {
              IFormatter formatter = new BinaryFormatter();
              formatter.Serialize(stream, obj);
            } catch (SerializationException err) {
              Console.WriteLine(err);
            }
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine("Exception: {0}", ex);
    }
    

    I hope that then you’ll get some helpful hints. In your got you might miss a failing File.Open.

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

Sidebar

Related Questions

http://pushbuttonengine.com/ I'd like to know if anyone has experienced any major (particularly performance) issues
This is on a 64 bit Windows Machine, also running Visual Studio 2010. A
Has anyone experienced an issue where WAS does not use the Windows username when
Has anyone experienced this issue - Blackberry stops responding to javaloader -usb after a
has anyone else experienced this . I have SP1 but i have to kill
Has anyone else experienced this? I have uninstalled and reinstalled TortoiseSVN as well as
I've been having some serious issues with Visual Studio 2010 as of late. It's
Visual Studio has a habit of opening the wrong file in my solution -
Has anyone had any issues while setting up their local development system with Mamp
Has anyone had experience using SSL with net.tcp binding in WCF? Ive read its

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.