用户控件的序列化问题 [英] serialization issue for usercontrol

查看:93
本文介绍了用户控件的序列化问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我陷入了一个问题.iam将我的整个类冷凝添加到哈希表中,然后将其添加到会话中.该类(PropertiesTabControl)已序列化.该类具有usercontrol属性
当我称赞它工作正常时,这会产生问题.我会发布代码和错误.

-------------------错误


iam stuck with a problem.iam adding my entire class condense to hash table then it is added to session.The class(PropertiesTabControl)is serialized .the class has a property for usercontrol
this is creating problem when i commended it is working fine i will post the code and error.

-------------------error

Type ''System.Web.UI.UserControl'' in Assembly ''System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'' is not marked as serializable.   at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type) 
   at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context) 
   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo() 
   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter) 
   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter) 
   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo) 
   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) 
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) 
   at System.Web.Util.AltSerialization.WriteValueToStream(Object value, BinaryWriter writer)  



------------------------错误




------------------------Error


PropertiesTabControl propertiesTabControl = new PropertiesTabControl();
         
           
           propertiesTabControl.Comments = userControl;   //UserControl..........
           SessionHandler.Insert<PropertiesTabControl>(Tabs.OrganizationPropertyTab, propertiesTabControl);


public static void Insert<T>(Tabs currentTab, T currentObject) where T : class
   {
       Hashtable tabCollection = GetObject();

       if (tabCollection != null)
       {
           //once the tabcollection is fetched then check
           //if the current tab exist in the session
           if (tabCollection.ContainsKey(currentTab))
           {
               tabCollection[currentTab] = currentObject;
           }
           else
           {
               tabCollection.Add(currentTab, currentObject);
           }
       }
   }







private static Hashtable GetObject()
   {
       if (HttpContext.Current.Session[TabControl] == null)
       {
           HttpContext.Current.Session[TabControl] = new Hashtable();
       }

       return HttpContext.Current.Session[TabControl] as Hashtable;
   }



-------------------------序列化类----------------------



-------------------------Serialized Class----------------------

[Serializable]
public class BaseTabControl
{


    private SaveOperation _saveOperation;
    private long _objectId;
    private long _objectInstanceId;
    private ObjectInstance _objectInstance;
    private long _currentUserId;
    private long _parentId;
    private string _relationShipType;
    private Instance _instance;
    private TabGroups _tabGroup;
   private UserControl _comments;



    public UserControl Comments
    {
        get { return _comments; }
        set { _comments = value; }
    }

    public SaveOperation SaveOperation
    {
        get { return _saveOperation; }
        set { _saveOperation = value; }
    }

    public long ObjectId
    {
        get { return _objectId; }
        set { _objectId = value; }
    }

    public long ObjectInstanceId
    {
        get { return _objectInstanceId; }
        set { _objectInstanceId = value; }
    }

    public enum Instance
    {
        Instance1,
        Instance2,
        Instance3,
        Instance4,
        Instance5,
        Instance6
    }


    public Instance CurrentInstance
    {

        get { return _instance; }
        set { _instance = value; }
    }
    public ObjectInstance CurrentObjectInstance
    {
        get { return _objectInstance; }
        set { _objectInstance = value; }
    }

    public long CurrentUserId
    {
        get { return _currentUserId; }
        set { _currentUserId = value; }
    }
    public long ParentId
    {
        get { return _parentId; }
        set { _parentId = value; }
    }
    public string RelationShipType
    {
        get { return _relationShipType; }
        set { _relationShipType = value; }
    }
    public TabGroups TabGroup
    {
        get { return _tabGroup; }
        set { _tabGroup = value; }
    }
}


/// <summary>
/// Summary description for PropertiesTab
/// </summary>
[Serializable]
public class PropertiesTabControl : BaseTabControl
{

    private PropertiesTab _propertiesTab;
    private DataObjectCollection<ObjectAttributeListValues> _objectAttributeListValuesCollection;
    private DataObjectCollection<MemberRoles> _memberRolesCollection;

    private DataObjectCollection<NonComplainceAttributes> _nonComplainceAttributesCollection;
    private TaskDO _taskDo;
    private MemberResourceGroup _memberResourceGroup;


    public PropertiesTab PropertiesTab
    {
        get { return _propertiesTab; }
        set { _propertiesTab = value; }
    }
    public DataObjectCollection<ObjectAttributeListValues> ObjectAttributeListValuesCollection
    {
        get { return _objectAttributeListValuesCollection; }
        set { _objectAttributeListValuesCollection = value; }
    }
    public DataObjectCollection<MemberRoles> MemberRolesCollection
    {
        get { return _memberRolesCollection; }
        set { _memberRolesCollection = value; }
    }

    public DataObjectCollection<NonComplainceAttributes> NonComplainceAttributesCollection
    {
        get { return _nonComplainceAttributesCollection; }
        set { _nonComplainceAttributesCollection = value; }
    }
    public TaskDO TaskDo
    {
        get { return _taskDo; }
        set { _taskDo = value; }
    }
    public MemberResourceGroup MemberResourceGroup
    {
        get { return _memberResourceGroup; }
        set { _memberResourceGroup = value; }
    }

推荐答案

UserControls不可序列化.像这样序列化它们是一个坏主意,最好是创建用户控件的数据对象表示并将其序列化.
UserControls are not serializable. It''s a bad idea to serialize them like this, it''s better to create data object representations of the usercontrols and serialize them instead.


这篇关于用户控件的序列化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆