用户控制错误原因何在? [英] error in user control why?
问题描述
输入'<> f__AnonymousTypee`3 [[System.Int64,mscorlib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089],[System.String,mscorlib,Version = 4.0.0.0,Culture =中性,PublicKeyToken = b77a5c561934e089],[System.String,mscorlib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089]]'在Assembly'App_Web_4prx32q4,Version = 0.0.0.0,Culture = neutral,PublicKeyToken = null'是没有标记为可序列化。
这是我的用户控制代码。在第一行if(ViewState [_lstDataSource] == null )
它会产生上述错误原因??
< span class =code-keyword> protected void Page_Load( object sender,EventArgs e )
{
尝试
{
if (ViewState [_lstDataSource ] == null)
ViewState [_lstDataSource] = null ;
}
catch (例外情况)
{
抛出 ex;
}
}
public IEnumerable< Object> getDataSource
{
get
{
return ( IEnumerable< Object>)(ViewState [ _ lstDataSource]);
}
set
{
ViewState [ _ lstDataSource] = value .ToList();
}
}
我在.aspx页面中调用了这个用户控件
btnExport.getDataSource = query;
btnExport.Export(query);
将以下属性添加到您的财产
< pre lang =c#> [可浏览( false )]
[EditorBrowsable(EditorBrowsableState.Never)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ]
public IEnumerable< object> getDataSource
{
get
{
return ( IEnumerable< object>)(ViewState [ _ lstDataSource]);
}
set
{
ViewState [ _ lstDataSource] = value .ToList();
}
}
1。这是一个完全错误的代码:
尝试
{
if (ViewState [_lstDataSource ] == null)
ViewState [_lstDataSource] = null ;
}
catch (例外情况)
{
抛出 ex;
}
为什么?如果ViewState [_ lstDataSource]
已经null
,则无需将其设置为null。并且catch(Exception ex){throw ex; }
没有任何其他东西只是破坏原始异常的callstack信息,它不会添加任何信息或提供任何帮助。
2。问题的根源在于其他地方。_lstDataSource
的类型在哪里定义?在那里你必须添加一个属性,例如
[Serializable]
public class SomeType
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??
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
btnExport.getDataSource =query;
btnExport.Export(query);
add below attributes to your property
[Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public IEnumerable<object> getDataSource { get { return (IEnumerable<object>)(ViewState["_lstDataSource"]); } set { ViewState["_lstDataSource"] = value.ToList(); } }
1. That's a totally wrong code:
try { if (ViewState[_lstDataSource"] == null) ViewState[_lstDataSource"] = null; } catch (Exception ex) { throw ex; }
Why? IfViewState["_lstDataSource"]
is alreadynull
, there is no need to set it to null. And acatch (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
[Serializable] public class SomeType
这篇关于用户控制错误原因何在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!