Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Type '<>f__AnonymousTypee`3[[System.Int64, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' in Assembly 'App_Web_4prx32q4, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.


This is my code of user control .In first Line if (ViewState[_lstDataSource"] == null)
it generates the above error why??


C#
protected void Page_Load(object sender, EventArgs e)
 {
     try
     {

         if (ViewState[_lstDataSource"] == null)
             ViewState[_lstDataSource"] = null;

     }
     catch (Exception ex)
     {
         throw ex;
     }

 }
 public IEnumerable<Object> getDataSource
 {
     get
     {
         return (IEnumerable<Object>)(ViewState["_lstDataSource"]);
     }
     set
     {
         ViewState["_lstDataSource"] = value.ToList();

     }
 }


I called this user control in my .aspx page
C#
btnExport.getDataSource =query;
               btnExport.Export(query);
Posted
Comments
Manoj B. Kalla 16-Jun-14 2:04am    
Can you show me your asp.net code also.

add below attributes to your property
C#
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public IEnumerable<object> getDataSource
{
    get
    {
       return (IEnumerable<object>)(ViewState["_lstDataSource"]);
    }
    set
    {
       ViewState["_lstDataSource"] = value.ToList();
    
    }
}
 
Share this answer
 
v2
1. That's a totally wrong code:
C#
try
{

    if (ViewState[_lstDataSource"] == null)
        ViewState[_lstDataSource"] = null;

}
catch (Exception ex)
{
    throw ex;
}

Why? If ViewState["_lstDataSource"] is already null, there is no need to set it to null. And a catch (Exception ex) { throw ex; } without anything else just destroys the callstack information of the original exception, it does not add any information or offer any help.

2. The source fo your problem is somewhere else. Where is the type of _lstDataSource defined? There you have to add an attribute, something like
C#
[Serializable]
public class SomeType
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900