类:Pet 包含属性 IList<Cat>.先创建IList<Pet>。然后序列化该数组报错。
请问有没解决方法?

解决方案 »

  1.   

    确认两个类都有序列化标记. 检查是否有不支持序列化的成员 增加[NonSerialized]特性.
      

  2.   

    确实使用的接口。因为使用的是NHibernate实例化对象。例如:
        [Serializable]
        public class BusinessType
        {
            public virtual string Id
            {
                get { return _id; }
                set { _id = value; }
            }
            public virtual string Name
            {
                get { return _name; }
                set { _name = value; }
            }
            public virtual IList<Module> ListModule
            {
                get { return _listModule; }
                set { _listModule = value; }
            }
         }    [Serializable]
        public class Module
        {
            public virtual string Id
            {
                get { return _id; }
                set { _id = value; }
            }
            public virtual string Name
            {
                get { return _name; }
                set { _name = value; }
            }
        }IList<BusinessType> b = new IList<BusinessType>();
    现在序列化b报错。就是问题没法序列化IList<Module> ListModule,说是接口问题。
      

  3.   


    // 摘要:
    //     指示一个类可以序列化。无法继承此类。
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Delegate, Inherited = false)]
    [ComVisible(true)]
    public sealed class SerializableAttribute : Attribute
    {
            // 摘要:
            //     初始化 System.SerializableAttribute 类的新实例。
            public SerializableAttribute();
    }明显不支持接口
      

  4.   

    不是使用List
    我试过了。这样NHibernate对象实例化的时候报错。
      

  5.   

    IList <BusinessType> b = new List <BusinessType>();