Я сериализую структуру, используя BinaryFormatter
, используя этот код:
private void SerializeObject(string filename, SerializableStructure objectToSerialize)
{
Stream stream = File.Open(filename, FileMode.Create);
BinaryFormatter bFormatter = new BinaryFormatter();
bFormatter.Serialize(stream, objectToSerialize);
stream.Close();
}
Какая objectToSerialize
- моя структура, я вызываю эту функцию следующим образом:
SerializableStructure s = new SerializableStructure();
s.NN = NN;
s.SubNNs = SubNNs;
s.inputs = inputs;
SerializeObject(Application.StartupPath + "\\Save\\" + txtSave.Text + ".bin", s);
Какой SerializableStructure
, а тип NN
, SubNNs
и входы сериализуемы. (входы содержат некоторые Points
, Rectangles
и общие списки).
Теперь, когда я запускаю свой код, мне присваивается эта ошибка:
Введите "MainProject.Main" в Assembly "MainProject, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null" не помечен как сериализуемый.
Почему мне дана эта ошибка? Главная моя форма, и эти переменные расположены в моей форме.
Я успешно сериализовал тип NN
с MemoryStream
и VB.NET, но я не знаю, почему я получаю эту ошибку?
Вот определение моих структур:
SerializableStructure:
[Serializable()]
public class SerializableStructure
{
public List<Inputs> inputs = new List<Inputs>();
public NeuralNetwork NN;
public NeuralNetwork[] SubNNs;
}
Входы:
[Serializable()]
public class Inputs
{
public string XPath { get; set; }
public string YPath { get; set; }
public string ImagePath { get; set; }
public string CharName { get; set; }
public string CharBaseName { get; set; }
public List<double> x { get; set; }
public List<double> y { get; set; }
public List<double> DotsX { get; set; }
public List<double> DotsY { get; set; }
public List<Point> GravityCenters { get; set; }
public List<Rectangle> Bounds { get; set; }
public override string ToString()
{
return CharName;
}
public Inputs(string xPath, string yPath, string imagePath, string charName, string charBaseName)
{
XPath = xPath;
YPath = yPath;
ImagePath = imagePath;
CharName = charName;
CharBaseName = charBaseName;
x = new List<double>();
y = new List<double>();
GravityCenters = new List<Point>();
Bounds = new List<Rectangle>();
}
}
Также NN
- очень большая структура (!).