在会话"mscorlib.dll中发生了'System.StackOverflowException'类型的未处理异常"

Mer*_*ert 1 .net c# asp.net

我正在尝试填充会话,如果它的null,在null检查时得到错误

public static int ReportGroupId()
{
        if (System.Web.HttpContext.Current.Session["ReportGroupId"] == null) <ERROR HERE>
        System.Web.HttpContext.Current.Session["ReportGroupId"] = BL.Reporting.GET.ReportGroupId();

        return Convert.ToInt32(System.Web.HttpContext.Current.Session["ReportGroupId"]);
}
Run Code Online (Sandbox Code Playgroud)

Hab*_*bib 9

你是递归调用的函数BL.Reporting.GET.ReportGroupId(),如果Sessionnull.这就是你得到Stackoverflow例外的原因.它将进入无限循环.

调试你的代码 ,你会发现,当session为null时,它会在第一个条件下再次调用你的方法.

我只能猜测你可能想调用一些不同的函数来获取GroupID它在会话中找不到的值.