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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:31:21+00:00 2026-05-16T02:31:21+00:00

I have a problem that I don’t know how to solve. I have have

  • 0

I have a problem that I don’t know how to solve.
I have have a Form that open a OpenFileDialog to add data.
But after I call OpenFileDialog.Show() I can’t save anything with BinaryFormatter.Serialize.
The strange thing is that I doesn’t even need to use the data that I have from the OpenFileDialog, only to open the dialog make the subsequent call to Serialize to stop working.

Stop working means that no new data is saved.

I don’t get any error messages or exceptions, it just silently fail.
Do anyone have any pointers to when the problem could be.
I used the XmlSerializer when I added the OpenFileDialog and switched to BinaryFormatter.Serialize in hope that it should be more resistant to whatever problem I have so I’m pretty sure it affects XmlSerializer to.

I’m using .NET 4.0

Relevant code (I hope) is:
Save:

    public void Save()
    {
        File.Delete(fileName);
        using (Stream stream = File.Open(fileName, FileMode.Create))
        {
            BinaryFormatter bin = new BinaryFormatter();
            bin.Serialize(stream, contactList);
        }

    }

Load:

  private void LoadContactList()
    {
        if (File.Exists(fileName))
        {
            using (Stream stream = File.Open(fileName, FileMode.Open))
            {
                BinaryFormatter bin = new BinaryFormatter();
                contactList = (List<Contact>)bin.Deserialize(stream);
            }
        }
        else
        {
            // start on a new database
        }
   }

use of OpenFileDialog:

   private void btnPhoto_Click(object sender, EventArgs e)
    {
        if (DialogResult.OK == ofdPhoto.ShowDialog(this.Parent))
        {
            // signalling that the dialog have been used have have
            // useful data
            ofdPhoto.Tag = (object)true;
        }
    }

What I am saving is List:

List<Contact> contactList;

I have only Person in the list

[Serializable]
public class Person : Contact
{
    #region variables and properties

    //public string Photo { get; set; }
    public string Photo;

    private string lastName;
    public string LastName
    {
        get { return lastName; }
        set { lastName = value; base.ComparisonKey = value; }
    }

    public string FirstName { get; set; }
    //  no contructor
}

Edit

In the end of the program I save all data:

  private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
    {
        data.Save();
    }

The file name path that I get with the OpenFileDialog is for a photo.
The path is stripped and only the file name is stored. That part I have checked.
The file name is stored in a Person object, the Person object is stored in List
and in the end of program the whole array is persisted.
End edit
It doesn’t depend on the format on the string I am loading

Edit: I have called Dispose on the OpenFileDialog before I save with the BinaryFormatter.Serializer
When I comment out the contents of btnPhoto_Click it BinaryFormatter.Serializer works.

I would appriciate any ideas.

  • 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-16T02:31:22+00:00Added an answer on May 16, 2026 at 2:31 am

    I didn’t saved my file with an absolute path but with just a file name. When OpenFileDialog was used the current directory was changed and the data, the array was stored in current directory that was a totally different place than in the beginning of the program.

    And when I restarted the program, the current directory was reset and all the data seemed to be thrown away.
    One solution is described in this link
    Or just save current directory in a field link

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

Sidebar

Related Questions

One problem that I come across regularly and yet don't have a solution to
I have a problem drawing something quickly in .NET. I don't think that any
I have the odd problem that I am not able to open the properties
I have a problem that confuses my users, being that although an item is
I have the problem that an specific step in Ant can only be executed
I have a problem that I would like have solved via a SQL query.
I have a problem that I feel is best implimented in a stand alone
I have a problem that seems like its a result of a deadlock-situation. Whe
I have encountered a problem that I have not come accross yet when setting
I have a tricky problem that I've been messing about with for a few

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.