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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:06:19+00:00 2026-06-11T11:06:19+00:00

I am trying to move the m_settings variable from the volatile to the persistent

  • 0

I am trying to move the m_settings variable from the volatile to the persistent records. I have tried adding the [serializable] attribute to the class and sending the m_settings variable to a file stream using a BinaryFormatter but I got an error saying that the file cannot be written, access to the file is denied. What am I doing wrong?

[Serializable] 
public class SettingsComponent : GH_Component
{
    public SettingsComponent(): base("LoadSettings", "LoadSettings", "Loading ini", "Extra", "Silkworm") { }


    public override void CreateAttributes()
    {
        m_attributes = new SettingsComponentAttributes(this);
    }


    string m_settings_temp;
    string[] m_settings;
    public void ShowSettingsGui()
    {
        var dialog = new OpenFileDialog { Filter = "Data Sources (*.ini)|*.ini*|All Files|*.*" };
        if (dialog.ShowDialog() != DialogResult.OK) return;

        m_settings_temp = File.ReadAllText(dialog.FileName);
        m_settings = m_settings_temp.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
        ExpireSolution(true);
    }



    protected override void SolveInstance(IGH_DataAccess DA)
    {
        if (m_settings == null)
        {
           AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "You must declare some valid settings");
           return;
        }
        else
        {  
                    FileStream fs = new FileStream("DataFiletemp.dat", FileMode.Create);
                    BinaryFormatter formatter = new BinaryFormatter();
                    try
                    {
                        formatter.Serialize(fs, m_settings);
                    }
                    catch (SerializationException e)
                    {
                        Console.WriteLine("Failed to serialize. Reason: " + e.Message);
                        throw;
                    }
                    finally
                    {
                        fs.Close();
                    }

                   DA.SetDataList(0, m_settings);
        }  

    }
  • 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-11T11:06:19+00:00Added an answer on June 11, 2026 at 11:06 am

    Arthur, if your m_settings object is not complex you can use project settings (application or user level). Here is sample code how you can save some project settings to app.config:

         [YourNamespace].Properties.Settings.Default["MyProperty"] = "Demo Value";
         [YourNamespace].Properties.Settings.Default.Save();
    

    And if you have the need for binary serialization you can use code like this:
    (serialized object and object of inheritance must be marked as serializable)

        /// <summary>
        /// Serializes object to file
        /// </summary>
        /// <param name="data"></param>
        /// <param name="FilePath"></param>
        public static void SerializeMyObject(object data, string FilePath)
        {
            System.IO.Stream stream = null;
            try
            {
                stream = System.IO.File.Open(FilePath, System.IO.FileMode.Create);
                System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bformatter =
                new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                bformatter.Serialize(stream, data);
                stream.Close();
                stream.Dispose();
            }
            catch (Exception ex)
            {
                try
                {
                    stream.Close();
                    stream.Dispose();
                }
                catch (Exception)
                {
                }
                throw new Exception(ex.Message);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to move the menu structure from a JMenu into a JMenuBar. The
I'm trying to move a MySQL database from a Linux machine to one running
I'm trying to move the data from one table to another based on names
I'm trying to move a control from one parent to another (if this will
I'm trying to get my company to move to ASP.NET MVC and away from
I have a div element that I'm trying, basically, to move wherever the user
I'm trying to move a java application from an old server to a new
I'm trying to move NServiceBus UnicastBusConfig from Web.config to (VB.NET) code and I'm having
I'm trying to move a joomla site from one person's hosting account to another.
In trying to get some labels in a TableLayoutPanel to move from the top

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.