title: Using BinaryFormatter to serialize a String[] variable within a class
body: <p>I am trying to move the <code>m_settings</code> variable from the volatile to the persistent records. I have tried adding the <code>[serializable]</code> attribute to the class and sending the <code>m_settings</code> variable to a file stream using a BinaryFormatter but I got an error saying that <code>the file cannot be written, access to the file is denied</code>. What am I doing wrong?</p>
  
  <pre><code>[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);
          }  
  
      }
  </code></pre>