简体   繁体   中英

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. 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
    • The other developers working on the same solution do not have this problem
  • Tried debugging the solution in VS2015 and 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. While one a breakpoint I look at a few variables.

  • public ActionResult Detail(Guid? id) > I can view the value of id
  • SomeObject item = someobjectRepository.GetItem(id).SingleOrDefault() > Gets the item but cant view its variables
  • Later in the code foreach(var subitem in item.Subitems) > I can view the values of 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.

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.

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. But if anyone runs into something like this I hope this can help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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