发生类型为'System.StackOverflowException'的未处理异常-使用Cache'd类 [英] An unhandled exception of type 'System.StackOverflowException' occurred - using Cache'd class

查看:108
本文介绍了发生类型为'System.StackOverflowException'的未处理异常-使用Cache'd类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如下课程:

I have a class as in the following:

public class activityDetail
{
  public string a { get; set; }
  public string b { get; set; }
}


然后我想做的就是在Cache.cs中定义一个singlton类,如下所示:


then what I want to do is define a singlton class in my Cache.cs as in the following:

public sealed class Cache
{
private static  readonly Cache cacheInstance = new Cache();
.
.
.
.
public activityDetail instanceofActivitydetail { get { return instanceofActivitydetail; } }


现在,在我的控制器中,我想引用此instanceofActivitydetail,如果我通过以下方式获取异常(某种类型的堆栈溢出)的方式进行引用:


Now, in my controller I want to reference this instanceofActivitydetail, if I do it the following way I get an exception (some type of stack overflow):

Cache.CacheInstance.instanceofActivitydetail.a = some value; 
Cache.CacheInstance.instanceofActivitydetail.b = some other value;


//一些值"只是为了简便起见,它实际上具有指定的已知值,但在此处共享它并不容易.
//因此,当编译器在每一行中均引发上述错误时,我认为我在Cache类中的定义丢失了某些内容,或者我在控制器上显示的上述调用丢失了某些内容.


// "some value" is just for ease it actually have a designated known value but it is not easy to share it here.
// so when the compiler eaches this line it throws the error mentioned above, I believe my defninition in the Cache class is missing something, or my call shown above from the controller is missing something.

推荐答案

此异常是最容易确定和修复的异常之一.几乎总是与未完成的递归或相互递归有关:
http://en.wikipedia.org/wiki/Recursion [ http://en.wikipedia.org/wiki/Mutual_recursion [
-SA
This exception is one of the easiest to nail down and fix. Almost always, it is related to unfinished recursion or mutual recursion:
http://en.wikipedia.org/wiki/Recursion[^],
http://en.wikipedia.org/wiki/Mutual_recursion[^].

Use the debugger, put a breakpoint where the exception is thrown. You will observe that the code is repeated many times in execution. To see where a call comes from, use "Call stack" debugger window. When you see what the calling code is repeated, move your breakpoint there, until you see the root of the problem.

—SA


公共活动详细信息instanceofActivitydetail {get;设置;}

并将以下内容放入控制器中(在使用Cache类/属性之前):

Cache.CacheInstance.instanceofActivitydetail = new activityDetai();
public activityDetail instanceofActivitydetail { get; set;}

and placed the following in the controller (before using the Cache class/property):

Cache.CacheInstance.instanceofActivitydetail = new activityDetai();


这篇关于发生类型为'System.StackOverflowException'的未处理异常-使用Cache'd类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆