estoy serializar una estructura mediante el uso de BinaryFormatter
utilizando este código:no marcadas como serializable error al serializar una clase
private void SerializeObject(string filename, SerializableStructure objectToSerialize)
{
Stream stream = File.Open(filename, FileMode.Create);
BinaryFormatter bFormatter = new BinaryFormatter();
bFormatter.Serialize(stream, objectToSerialize);
stream.Close();
}
Qué objectToSerialize
es mi estructura, llamaré a esta función como esta:
SerializableStructure s = new SerializableStructure();
s.NN = NN;
s.SubNNs = SubNNs;
s.inputs = inputs;
SerializeObject(Application.StartupPath + "\\Save\\" + txtSave.Text + ".bin", s);
Que SerializableStructure
, y Tipo de NN
, SubNNs
y las entradas son serializables. (las entradas contienen algunas Points
, Rectangles
y listas genéricas).
Ahora, Cuando ejecuto mi código, me da este error:
Type 'MainProject.Main' in Assembly 'MainProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
Por qué me dan este error? Principal es mi formulario, y estas variables se encuentran en mi formulario.
He serializado con éxito Tipo de NN
con MemoryStream
y VB.NET, pero no sé por qué me sale este error?
Aquí es la definición de mis estructuras:
SerializableStructure:
[Serializable()]
public class SerializableStructure
{
public List<Inputs> inputs = new List<Inputs>();
public NeuralNetwork NN;
public NeuralNetwork[] SubNNs;
}
Entradas:
[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>();
}
}
también NN
es muy grande estructura (!).
¿Podría proporcionar la definición de la estructura que está serializando? Me interesan los tipos de SubNN, NN y entradas. – dasblinkenlight
@dasblinkenlight He actualizado mi pregunta. –
¿NeuralNetwork tiene delegados? – dasblinkenlight