【问题标题】:Why is the Visual Studio 2013 debugger closing without error when I try to expand Model properties?当我尝试展开模型属性时,为什么 Visual Studio 2013 调试器会正常关闭?
【发布时间】:2015-04-23 15:47:48
【问题描述】:

我有一个使用 Entity Framework Code First 的小型 ASP.NET MVC5 项目。我在控制器中放置了一个断点,以便我可以检查变量的内容,以确保它们都包含它们应该包含的内容。一个这样的变量是我从上下文中查询的复杂模型对象,当我尝试扩展该对象以查看其属性时,调试器只是简单地关闭而没有明显的错误消息。我得到的唯一解释是在输出中:

The program '[10820] iisexpress.exe: Program Trace' has exited with code 0 (0x0).
The program '[10820] iisexpress.exe' has exited with code -2147023895 (0x800703e9).
The program '[12128] iexplore.exe' has exited with code -1 (0xffffffff).

我查看了退出代码 -2147023895 (0x800703e9),发现这是一个堆栈溢出问题,实际上无助于找出导致它的原因。

最不寻常的是,如果我让应用程序运行,它会毫无问题地加载页面,而且似乎根本不会抛出任何错误。这是怎么回事?

这是我的相关代码:

控制器

public ActionResult Index()
{
    //This is the line that crashed the debugger if I try to expand quarter
    //after it is filled. There will only ever by one item marked isCurrent.
    Quarter quarter = db.Quarter.First(x => x.isCurrent == true);

    ...
}

型号

public class Quarter
{
    public int Id {get; set;}
    public Enums.QuarterEnum Quarter {get; set;}
    public string Year {get; set;}
    public bool isCurrent {get; set;}
    [NotMapped]
    public string QuarterAndYear {get{ return QuarterAndYear; }}
}

查看

...
@Html.LabelFor(model => model.Quarter.Quarter)
@Html.DisplayFor(model => model.Quarter.Quarter)
...

【问题讨论】:

    标签: c# asp.net-mvc entity-framework debugging visual-studio-2013


    【解决方案1】:

    我四处寻找解决此问题的方法,但找不到任何真正帮助我的东西,因此我选择在此处发布此问题,并解释为什么会发生这种情况以及修复它的超级简单更改。

    问题出在模型中:

    public string QuarterAndYear {get{ return QuarterAndYear; }}
    

    我的一个粗心错误告诉它自己返回,这让我非常头疼,试图弄清楚它为什么会崩溃而没有错误消息。应该是:

    public string QuarterAndYear {get{ return Quarter.toString() + " Quarter of " + Year;}}
    

    因为我实际上并没有在视图中引用 QuarterAndYear,所以当我加载页面时没有引发任何错误,并且它似乎运行完美。但是,当我在调试时尝试查看 Quarter 对象的属性时,它试图解析 QuarterAndYear(它正在返回自身)并导致调试器崩溃。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-24
      • 1970-01-01
      • 2015-03-18
      • 2011-05-19
      相关资源
      最近更新 更多