using System;
using System.Runtime. Serialization;
using System.IO;
using System.Runtime. Serialization.F ormatters.Binar y;
namespace MySerialize
{
/// <summary>
/// Summary description for MySerialize.
/// </summary>
[Serializable]
public class MySerialize: ISerializable
{
string name = "Sheraze";
private MySerialize()
{
}
public MySerialize(str ing name )
{
this.name = name;
}
void ISerializable.G etObjectData(Se rializationInfo info,StreamingC ontext
context)
{
info.SetType(ty peof(MySerializ e));
}
}
public class MyTestApp
{
[STAThread]
public static void Main()
{
FileStream fs = new FileStream("mys erialize.txt", FileMode.Create );
BinaryFormatter formatter = new BinaryFormatter ();
MySerialize[] obj1 = {new MySerialize("Na me1") , new MySerialize("Na me2")};
formatter.Seria lize(fs, obj1);
fs.Position = 0;
MySerialize[] obj2 = (MySerialize[]) formatter.Deser ialize(fs);
fs.Close();
}
}
}
i get an error on this line saying
MySerialize[] obj2 = (MySerialize[]) formatter.Deser ialize(fs);
Additional information: The constructor to deserialize an object of type
MySerialize.MyS erialize was not found.
why is that and how do i resolve it?
thnx
using System.Runtime. Serialization;
using System.IO;
using System.Runtime. Serialization.F ormatters.Binar y;
namespace MySerialize
{
/// <summary>
/// Summary description for MySerialize.
/// </summary>
[Serializable]
public class MySerialize: ISerializable
{
string name = "Sheraze";
private MySerialize()
{
}
public MySerialize(str ing name )
{
this.name = name;
}
void ISerializable.G etObjectData(Se rializationInfo info,StreamingC ontext
context)
{
info.SetType(ty peof(MySerializ e));
}
}
public class MyTestApp
{
[STAThread]
public static void Main()
{
FileStream fs = new FileStream("mys erialize.txt", FileMode.Create );
BinaryFormatter formatter = new BinaryFormatter ();
MySerialize[] obj1 = {new MySerialize("Na me1") , new MySerialize("Na me2")};
formatter.Seria lize(fs, obj1);
fs.Position = 0;
MySerialize[] obj2 = (MySerialize[]) formatter.Deser ialize(fs);
fs.Close();
}
}
}
i get an error on this line saying
MySerialize[] obj2 = (MySerialize[]) formatter.Deser ialize(fs);
Additional information: The constructor to deserialize an object of type
MySerialize.MyS erialize was not found.
why is that and how do i resolve it?
thnx
Comment