none
override void GetObjectData(SerializationInfo info, StreamingContext context) 引发“System.OutOfMemoryException”的异常 RRS feed

  • 问题

  •    [Serializable]
        public partial class MyDataSet : DataSet, ISerializable
        {
            public MyDataSet()
            { }
            protected MyDataSet(SerializationInfo info, StreamingContext context)  
            {}
            public override void GetObjectData(SerializationInfo info, StreamingContext context)
            {
                base.GetObjectData(info, context);
            }
        }
            private void btn序列化_Click(object sender, EventArgs e)
            {      
                byte[] buffer = null;
                IFormatter formater = new BinaryFormatter();
                MemoryStream ms = new MemoryStream();
                MemoryStream fs = new MemoryStream();
                DataTable dt=dsSYS_TestM.Tables[0].Copy();
                MyDataSet md = new MyDataSet();
                md.Tables.Add(dt);
                formater.Serialize(ms, md);
                buffer = new byte[(int)ms.Length];
                ms.Position = 0;
                ms.Read(buffer, 0, (int)ms.Length);
                ms.Close();
                IFormatter bina = new BinaryFormatter();
                MemoryStream ms1 = new MemoryStream(buffer);
                MyDataSet d = (MyDataSet)bina.Deserialize(ms1);
                ms1.Close();
            }
    测试资料有10W笔,如果dataset填充资料较多(大于90000笔),序列化时,代码执行到base.GetObjectData(info, context); 这里会提示“System.OutOfMemoryException”异常错误,请大家帮忙分析是何原因造成,难道才这点资料就内存溢出了么
    2012年8月7日 6:49

答案