简体   繁体   English

Visual Studio 2017-在调试模式下无法查看变量

[英]Visual Studio 2017 - Cant view variables when in debug mode

I have been trying to figure this problem out for a while now. 我已经尝试解决这个问题已有一段时间了。

I work in Visual Studio 2017 and have many solutions I work on. 我在Visual Studio 2017中工作,并且有许多解决方案。 Every single one of them shows me variables and their values when I am debugging it except one. 除调试变量外,每个调试变量中的每一个都向我显示变量及其值。 It runs perfectly tho. 它运行完美。

What I have done: 我做了什么:

  • Played around with managed compatibility mode 在托管兼容模式下玩耍
  • Clean and rebuild and all those basics 清理和重建以及所有这些基础知识
  • Remove local solution and get it fresh from Git 删除本地解决方案,然后从Git重新获取
    • The other developers working on the same solution do not have this problem 使用相同解决方案的其他开发人员没有此问题
  • Tried debugging the solution in VS2015 and VS2019 Preview 尝试在VS2015和VS2019 Preview中调试解决方案

Cant seem to fix this, any ideas on what more I can try? 似乎无法解决此问题,我还有什么可以尝试的想法?

Edit : Clarification, I can step through the code when debugging, but I cant view value of variables. 编辑 :澄清,我可以在调试时逐步执行代码,但是无法查看变量的值。

EditEdit : Was doing some testing, and I have new information. EditEdit :正在做一些测试,我有新的信息。 While one a breakpoint I look at a few variables. 虽然是一个断点,但我看了几个变量。

  • public ActionResult Detail(Guid? id) > I can view the value of id public ActionResult Detail(Guid?id)>我可以查看id的值
  • SomeObject item = someobjectRepository.GetItem(id).SingleOrDefault() > Gets the item but cant view its variables SomeObject item = someobjectRepository.GetItem(id).SingleOrDefault()>获取项目但无法查看其变量
  • Later in the code foreach(var subitem in item.Subitems) > I can view the values of subitem. 稍后在代码foreach(item.Subitems中的var subitem)>中,我可以查看subitem的值。

EditEditEdit 编辑编辑

Variables that cannot be view all have become stale. 无法全部查看的变量已过时。

For testing puroses I removed all the variables of my model so is completely empty then I initialize it 为了测试姿势,我删除了模型的所有变量,因此完全为空,然后将其初始化

public MySuperModel()
{
}

Initialization 初始化

MySuperModel model = new MySuperModel();

Viewing model by either hovering or adding to watch/quickwatch yields the message that it has become stale. 通过将鼠标悬停或添加到手表/快速手表来查看模型,会产生一条消息,表明它已过时。

And so forth, its very strange 等等,这很奇怪

screenshot - not showing 屏幕截图-未显示 屏幕截图-未显示

screenshot - showing 屏幕截图-显示 屏幕截图-显示

List<ClassA> list = new List<ClassA>();
ClassA retVal = list.Where(o => o.MyProperty1 == 1).FirstOrDefault();

Here will be no exception (error), retVal is null and you will not see the properties or the values of the properties of the class. 这里不会有异常(错误), retValnull,并且您将看不到类的属性或属性的值。

All you have to do is add some items into the list. 您所要做的就是将一些项目添加到列表中。

List<ClassA> list = new List<ClassA>();
list.Add(new ClassA() { MyProperty1 = 1, MyProperty2 = 2 }); //adding item
ClassA retVal = list.Where(o => o.MyProperty1 == 1).SingleOrDefault();

I have found a solution to my problem, tho I dont know why it works. 我已经找到了解决我问题的方法,但是我不知道它为什么起作用。

I will try to explain. 我会尽力解释。

I have a model that contains to IEnumerables. 我有一个包含IEnumerables的模型。

Model 模型

public SuperModel()
{
      public IEnumerable<MemberObject> memberList1{get; set;}
      public IEnumerable<MemberObject> memberList2{get; set;}
}

Controller 控制者

public ActionResult Detail(Guid? id)
{
    //Model initialized
    SuperModel model =  GetTheModel();

    //Then there were 2 foreach loops throu my einumerables
    foreach(var item in model.memberList1)
    {
        //Do things
    }
    foreach(var item in model.memberList2)
    {
        //Do things
    }

}

This broke the debugger, If I only left 1 of the loops in debugger worked. 如果我只在调试器中保留其中一个循环,那么调试器就中断了。

Workaround 解决方法

public ActionResult Detail(Guid? id)
{
    //Model initialized
    SuperModel model =  GetTheModel();

    //Then there were 2 foreach loops throu my einumerables
    model.memberList1.ToList().Foreach((item) => 
    { 
        //Do Things
    });
    model.memberList2.ToList().Foreach((item) => 
    { 
        //Do Things
    });

}

Fin

I have no idea why using the .ForEach methods works while using a classic foearch() loop does not. 我不知道为什么使用.ForEach方法有效而使用经典的foearch()循环无效。 But if anyone runs into something like this I hope this can help. 但是,如果有人遇到类似问题,希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM