21
निम्न उदाहरण को देखते हुए:deserialization के दौरान संरक्षक नहीं मिला?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace SerializationTest
{
[Serializable]
class Foo : Dictionary<int, string>
{
}
class Program
{
static void Main(string[] args)
{
Foo foo = new Foo();
foo[1] = "Left";
foo[2] = "Right";
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
formatter.Serialize(stream, foo);
stream.Seek(0, SeekOrigin.Begin);
formatter.Deserialize(stream);
}
}
}
अंतिम पंक्ति में, क्योंकि फ़ॉर्मेटर फू करने के लिए निर्माता नहीं मिल सकता है एक SerializationException फेंक दिया है। ऐसा क्यों है?
और सभी क्योंकि शब्दकोश ISERializable लागू करता है, निश्चित रूप से ... –
SerializationInfo और StreamingContext कक्षाओं के लिए नोट, वे ** सिस्टम में हैं। रनटाइम। सरलीकरण ** नामस्थान। पूर्ण पथ ** System.Runtime.Serialization.SerializationInfo ** है। – Wappenull