m_settings
変数を揮発性レコードから永続レコードに移動しようとしています。[serializable]
クラスに属性を追加m_settings
し、BinaryFormatter を使用して変数をファイル ストリームに送信しようとしましたが、エラーが発生しましたthe file cannot be written, access to the file is denied
。私は何を間違っていますか?
[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);
}
}