我得到了有一个自定义类辞书,并列出了例外。 例子:随机InvalidCastException的
List<DisplayAllQuestionsTable> dsa = (List<DisplayAllQuestionsTable>)Session["Display"];
演员适用于10〜20倍,当我使用Session..and然后它开始抛出异常。如果我活着的电脑大约20-30分钟..我可以像往常一样启动我的Web应用程序,并在启动代码20次后,它会抛出相同的异常。为什么会发生?
现在我测试了另一种更简单的代码与雪村:
public partial class Default2 : System.Web.UI.Page
{
List<meem> moom = new List<meem>();
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 0; i < 20; i++)
{
meem m = new meem();
m.i = i;
moom.Add(m);
}
Session["meem"] = moom;
Button ew = new Button();
ew.Text = "Press me";
ew.Click += Click;
PlaceHolder1.Controls.Add(ew);
}
void Click(object sender, EventArgs e)
{
List<meem> moom = (List<meem>)Session["meem"];
foreach (var item in moom)
{
Label l = new Label();
l.Text = item.i.ToString();
this.Controls.Add(l);
}
}
}
class meem
{
public int i;
}
和它的作品100%
,我得到异常:
Server Error in '/WebSite10' Application.
[A]System.Collections.Generic.List`1[DisplayAllQuestionsTable] cannot be cast to
[B]System.Collections.Generic.List`1[DisplayAllQuestionsTable].
Type A originates from 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither'
at location 'D:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'.
Type B originates from 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither'
at location 'D:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: [A]System.Collections.Generic.List`1[DisplayAllQuestionsTable] cannot be cast to [B]System.Collections.Generic.List`1[DisplayAllQuestionsTable]. Type A originates from 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'D:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Type B originates from 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'D:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'.
想必有人顺手把东西进入会议[“显示”。当你得到异常时,你可以检查Session [“Display”]中的内容。 – 2011-06-16 10:16:50
如何进行一些调试并检查Session [“Display”]的值是什么时候爆炸? – 2011-06-16 10:17:02
您的会话是否超时?你的AppPool被销毁了吗? – 2011-06-16 10:18:13