序列化总是提示Arraylist中的对象不可序列化
---给出你的对象定义来看看

解决方案 »

  1.   

    ArrayList中元素
    [Serializable()]
    public struct DataFile
    {
    public DateTime MonitorTime;
    public int OperationType;
    public string Dictionary;
    public string FileName;
    public int ID;
    public string IP;
    }
    被序列化的对象
    [Serializable()]
    public class Package
    {
    public Package()
    {
    PackageSerial = 0;
    DataType = DataType.None;
    Data = null;
    Memo = "";
    }
    #region 数据报的数据项 /// <summary>
    /// 包的序号
    /// </summary>
    public int PackageSerial; /// <summary>
    // 包的类型
    /// </summary>
    public DataType DataType; /// <summary>
    // 包的数据区
    /// </summary>
    public ArrayList Data; /// <summary>
    /// 备注信息
    /// </summary>
    public string Memo; /// <summary>
    /// 通信包的包头信息
    /// </summary>
    [NonSerialized()]
    public static string PackageHeader =  "Package;Verion=Ver1.0;       "; #endregion
    }
      

  2.   

    楼主,没有问题啊DataFile df = new DataFile();
    df.Dictionary = "1";
    df.FileName = "2";
    df.ID = 1;
    df.IP = "#";
    df.MonitorTime = DateTime.Now;
    df.OperationType = 1; Package p = new Package();
    p.Data = new ArrayList();
    p.Data.Add(p); FileStream fs = new FileStream("DataFile.dat", FileMode.Create); BinaryFormatter formatter = new BinaryFormatter();
    formatter.Serialize(fs,p);
      

  3.   

    是不是Data = null;不能序列化,改成Data=new ArrayList();试试。