ISerializable을 밑줄려고했는데이 문제에 난처함을 보였습니다. 나는 "Serializable"속성으로 두 클래스를 만들었다. ISerializable에서 파생 된 클래스는 하나 뿐이며 GetObjectData가 정의되어 있습니다. 이 클래스를 A라고 부르 자. ISerializable에서 GetObjectData가 파생되지 않았다. 이 클래스를 B로 부르겠습니다. 클래스 A에 대한 임의의 특수 생성자를 제공하지 않았습니다. 이제 런타임 클래스 A에서 "특수 생성자가 누락되었습니다"와 같은 오류가 표시됩니다. 구문은 두 클래스 모두 동일합니다. 따라서 오류는 다른 것일 수 있지만 생성자와 관련해서는 안됩니다. 그렇지 않으면 클래스 B에 대해서도 동일한 오류가 발생합니다. 아래 코드를 참조하십시오. 아무도 그 이유를 말할 수 있습니까?
참고 : 나는 윈도우 7 사용하고 있습니다 - 비주얼 스튜디오 2010형식 T의 개체를 deserialize하는 생성자를 찾을 수 없습니다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace Delete_This
{
[Serializable]
class After_Implementing_ISerializable:ISerializable
{
int a;
string b;
public After_Implementing_ISerializable(int a, string b)
{
this.a = a;
this.b = b;
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
}
public void Check()
{
After_Implementing_ISerializable s = new After_Implementing_ISerializable(15, "100");
FileStream fs = new FileStream("temp.xml", FileMode.OpenOrCreate);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs, s);
fs.Close();
fs = new FileStream("temp.xml", FileMode.OpenOrCreate);
After_Implementing_ISerializable d = (After_Implementing_ISerializable)bf.Deserialize(fs);
fs.Close();
}
}
[Serializable]
class Without_Implementing_ISerializable
{
int a;
string b;
public Without_Implementing_ISerializable(int a,string b)
{
this.a = a;
this.b = b;
}
public void Check()
{
Without_Implementing_ISerializable s = new Without_Implementing_ISerializable(15, "100");
FileStream fs = new FileStream("temp.xml", FileMode.OpenOrCreate);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs, s);
fs.Close();
fs = new FileStream("temp.xml", FileMode.OpenOrCreate);
Without_Implementing_ISerializable d = (Without_Implementing_ISerializable)bf.Deserialize(fs);
fs.Close();
}
}
class Program
{
static void Main(string[] args)
{
Without_Implementing_ISerializable s = new Without_Implementing_ISerializable(5,"Five");
s.Check();
After_Implementing_ISerializable s1 = new After_Implementing_ISerializable(6, "Six");
s1.Check();
}
}
}
와 64 비트 이것은 내가
"The constructor to deserialize an object of type 'Delete_This.After_Implementing_ISerializable' was not found."}
@ Raymond 토픽에 대한 좋은 편집을 해주셔서 감사합니다. – prabhakaran