Visual Studio 2015的调试问题 [英] Debugging problem with Visual Studio 2015

查看:110
本文介绍了Visual Studio 2015的调试问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用Visual Studio 2015社区版。我只是尝试调试一段代码,但我在调试器上遇到了困难。我使用的代码是在帖子的最后。



代码在已加载事件中正确连接并执行的WPF窗口。我面临的症状:



  • 线路断点

    Hi,

    I'm using Visual Studio 2015 Community edition. I just tried to debug a piece of code but I'm having a hard time with the debugger. The code I used is in the end of the post.

    The code is inside a Loaded event of a WPF window which is wired correctly and executed. Symptoms I'm facing:


    • Breakpoint on line

      System.Xml.Linq.XElement element1 = System.Xml.Linq.XElement.Parse(xml1);



      根本没有被击中

    • 线路上的断点


      is not hit at all

    • Breakpoint on line

      System.Xml.Linq.XElement element2 = System.Xml.Linq.XElement.Parse(xml2);



      正确点击

    • 元素1上使用QuickWatch 我得到


      is hit correctly

    • Using QuickWatch on element1 I get

      error CS0103: The name 'element1' does not exist in the current context

    • 元素2上使用QuickWatch 正常工作
    • xml1 上使用QuickWatch给出

    • Using QuickWatch on element2 works correctly
    • Using QuickWatch on xml1 gives

      error CS0103: The name 'xml1' does not exist in the current context

    • xml2上使用QuickWatch 正常工作
    • 最后的循环重复三次但System.Diag ...行根本没有执行
    •         private void Window_Loaded(object sender, RoutedEventArgs e)
              {
                  string xml1 = @"<hostgroup id=""2080"">
          <instance_id>1</instance_id>
          <hostgroup_name>Avanade-Hypervisors</hostgroup_name>
          <members>
            <host id=""2061"">
              <host_name>ZACN-PSPR-HVR13</host_name>
            </host>
            <host id=""2062"">
              <host_name>ZACN-PSPR-HVR14</host_name>
            </host>
            <host id=""2063"">
              <host_name>ZACN-PSPR-HVR15</host_name>
            </host>
          </members>
      </hostgroup>";
      
                  string xml2 = @"<hoststatuslist>
       <hoststatus id=""49294"">
          <host_id>2061</host_id>
          <name>ZACN-VSPR-WAP02</name>
          <display_name>ZACN-PSPR-HVR13</display_name>
          <alias>management_servers</alias>
          <status_update_time>2015-09-19 08:00:31</status_update_time>
          <last_state_change>2015-09-18 19:25:06</last_state_change>
          <last_hard_state_change>2015-09-16 18:18:04</last_hard_state_change>
          <last_time_up>2015-09-19 08:00:31</last_time_up>
          <last_time_down>2015-09-18 19:25:06</last_time_down>
        </hoststatus>
      <hoststatus id=""49294"">
          <host_id>2062</host_id>
          <name>ZACN-VSPR-WAP02</name>
          <display_name>ZACN-PSPR-HVR14</display_name>
          <alias>linux_servers</alias>
          <status_update_time>2015-09-19 06:00:31</status_update_time>
          <last_state_change>2015-09-18 19:25:06</last_state_change>
          <last_hard_state_change>2015-09-16 18:18:04</last_hard_state_change>
          <last_time_up>2015-09-19 08:00:31</last_time_up>
          <last_time_down>2015-09-18 19:25:06</last_time_down>
        </hoststatus>
      <hoststatus id=""49294"">
          <host_id>2063</host_id>
          <name>ZACN-VSPR-WAP02</name>
          <display_name>ZACN-PSPR-HVR15</display_name>
          <alias>localhost</alias>
          <status_update_time>2015-09-19 09:00:31</status_update_time>
          <last_state_change>2015-09-18 19:25:06</last_state_change>
          <last_hard_state_change>2015-09-16 18:18:04</last_hard_state_change>
          <last_time_up>2015-09-19 08:00:31</last_time_up>
          <last_time_down>2015-09-18 19:25:06</last_time_down>
        </hoststatus>
      </hoststatuslist>";
      
                  System.Xml.Linq.XElement element1 = System.Xml.Linq.XElement.Parse(xml1);
      
                  System.Xml.Linq.XElement element2 = System.Xml.Linq.XElement.Parse(xml2);
      
                  var querya = from item1 in element1.Descendants("host")
                               join item2 in element2.Descendants("hoststatus")
                               on item1.Attribute("id").Value equals item2.Elements("host_id").First().Value
                               select new
                               {
                                   Host = item2.Elements("display_name").First().Value,
                                   UpTime = item2.Elements("last_time_up").First().Value,
                                   Alias = item2.Elements("alias").First().Value
                               };
      
                  foreach(var a in querya)
                  {
                      System.Diagnostics.Debug.WriteLine(a.Host);
                  }
              }

      推荐答案

      有什么提示我可以试试吗?

      将其关闭再重新打开? :笑:



      说真的,我会尝试一个干净而完整的重建,只是为了检查它是不是没有抛出摇晃而没有构建最新版本。 (在各种版本中,我已经和VS一起玩了几次 - 令人沮丧)。而且我也会把它关闭再重新打开......





      你试过看IL吗?看看它产生了什么?

      [/ edit]



      (根据要求发布为解决方案:谨慎提出建议为一个解决方案,所以我可以评论并接受它。)
      "Any hints what I could try?"
      Turn it off and back on again? :laugh:

      Seriously, I'd try a clean and full rebuild, just to check that it hasn't thrown a wobbly and not built the latest version. (I've had that a couple of times with VS in various versions - frustrating). And I'd turn it off and back on again as well...

      [edit]
      Have you tried looking at the IL to see what it has generated?
      [/edit]

      (Posted as solution as per request: "Care to put the suggestion as a solution so I could comment and accept it.")


      这篇关于Visual Studio 2015的调试问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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