をシリアル化するときのように、シリアライズエラーがマークされていない:私はこのコードを使用して<code>BinaryFormatter</code>を使用して構造をシリアル化していたクラス
objectToSerialize
は私の構造体である
private void SerializeObject(string filename, SerializableStructure objectToSerialize)
{
Stream stream = File.Open(filename, FileMode.Create);
BinaryFormatter bFormatter = new BinaryFormatter();
bFormatter.Serialize(stream, objectToSerialize);
stream.Close();
}
、私はこのように、この関数を呼び出しています:
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
および一般リストが含まれています)。私は私のコードを実行すると
は今、私はこのエラーを与えています:
Type 'MainProject.Main' in Assembly 'MainProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
私はこのエラーを与えてるのはなぜ? Mainは私のフォームであり、これらの変数は私のフォームにあります。
のタイプを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
非常に大きな構造体です(!)。
シリアル化している構造の定義を教えてください。私はSubNN、NN、入力のタイプに興味があります。 – dasblinkenlight
@dasblinkenlight質問を更新しました。 –
NeuralNetworkに代理人はいますか? – dasblinkenlight