簡體   English   中英

Visual Studio 2017-在調試模式下無法查看變量

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

我已經嘗試解決這個問題已有一段時間了。

我在Visual Studio 2017中工作,並且有許多解決方案。 除調試變量外,每個調試變量中的每一個都向我顯示變量及其值。 它運行完美。

我做了什么:

  • 在托管兼容模式下玩耍
  • 清理和重建以及所有這些基礎知識
  • 刪除本地解決方案,然后從Git重新獲取
    • 使用相同解決方案的其他開發人員沒有此問題
  • 嘗試在VS2015和VS2019 Preview中調試解決方案

似乎無法解決此問題,我還有什么可以嘗試的想法?

編輯 :澄清,我可以在調試時逐步執行代碼,但是無法查看變量的值。

EditEdit :正在做一些測試,我有新的信息。 雖然是一個斷點,但我看了幾個變量。

  • public ActionResult Detail(Guid?id)>我可以查看id的值
  • SomeObject item = someobjectRepository.GetItem(id).SingleOrDefault()>獲取項目但無法查看其變量
  • 稍后在代碼foreach(item.Subitems中的var subitem)>中,我可以查看subitem的值。

編輯編輯

無法全部查看的變量已過時。

為了測試姿勢,我刪除了模型的所有變量,因此完全為空,然后將其初始化

public MySuperModel()
{
}

初始化

MySuperModel model = new MySuperModel();

通過將鼠標懸停或添加到手表/快速手表來查看模型,會產生一條消息,表明它已過時。

等等,這很奇怪

屏幕截圖-未顯示 屏幕截圖-未顯示

屏幕截圖-顯示 屏幕截圖-顯示

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

這里不會有異常(錯誤), retValnull,並且您將看不到類的屬性或屬性的值。

您所要做的就是將一些項目添加到列表中。

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();

我已經找到了解決我問題的方法,但是我不知道它為什么起作用。

我會盡力解釋。

我有一個包含IEnumerables的模型。

模型

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

控制者

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
    }

}

如果我只在調試器中保留其中一個循環,那么調試器就中斷了。

解決方法

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
    });

}

我不知道為什么使用.ForEach方法有效而使用經典的foearch()循環無效。 但是,如果有人遇到類似問題,希望對您有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM