错误 - 未标记为可序列化 [英] Error - is not marked as serializable
问题描述
我得到的错误是:
Type 'OrgPermission' in Assembly 'App_Code.ptjvczom, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
这是我的代码:
我有一个 gridview,它使用以下数据源:
I have a gridview, that uses the following DataSource:
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetOrgList"
TypeName="Org">
<SelectParameters>
<asp:SessionParameter Name="orgCodes" SessionField="UserOrgs" Type="Object" />
<asp:Parameter DefaultValue="Y" Name="active" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
我在页面加载中设置会话变量,如下所示:
I set the session variable in my page load like so:
User cUser = new User(userid);
//make sure the user is an Admin
List<OrgPermission> orgs = new List<OrgPermission>();
foreach(OrgPermission org in cUser.orgs)
{
if (org.type=='admin')
{
orgs.Add(org);
}
}
Session["UserOrgs"] = orgs;
我的用户类如下所示:
public class OrgPermission
{
public string Org { get; set; }
public List<string> type { get; set; }
public OrgPermission()
{ }
}
public class cUser
{
public string userid { get; set; }
public List<OrgPermission> orgs { get; set; }
public clsUser(string username)
{
//i set everything here
}
}
我不明白为什么它会损坏,我可以在不使其可序列化的情况下使用它吗?
I can't understand why it's breaking, can I use it without making it serializable?
我尝试调试,会话变量设置得很好,然后它进入 GetOrgList 并返回正确的结果,但页面没有加载,我收到上述错误.
I tried to debug, and the session variable sets just fine, it then goes into the GetOrgList and returned correct results, but the page does not load and I get the error above.
这是我的 GetOrgList 函数的一个片段:
Here is a snippet of my GetOrgList function:
public DataTable GetOrgList(List<OrgPermission> orgCodes, string active)
{
string orgList = null;
//code to set OrgList using the parameter is here.
DataSet ds = new DataSet();
SqlConnection conn = new SqlConnection(cCon.getConn());
SqlCommand cmd = new SqlCommand("sp_GetOrgList", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@orgList", orgList));
cmd.Parameters.Add(new SqlParameter("@active", active));
conn.Open();
SqlDataAdapter sqlDA = new SqlDataAdapter();
sqlDA.SelectCommand = cmd;
sqlDA.Fill(ds);
conn.Close();
return ds.Tables[0];
}
推荐答案
您需要为要序列化的类添加 Serializable
属性.
You need to add a Serializable
attribute to the class which you want to serialize.
[Serializable]
public class OrgPermission
这篇关于错误 - 未标记为可序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!