visual studio 2010调试器 - 步入“if”尽管条件虚假 [英] visual studio 2010 debugger - steps into an "if" statement despite condition false

查看:179
本文介绍了visual studio 2010调试器 - 步入“if”尽管条件虚假的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VS 2010 Professional(Windows 7 Professional 64),使用WCF 4.0编写。
我有以下代码:

  if(responseMessage.StatusCode == HttpStatusCode.NotFound)
{
抛出新的ContentNotFoundException(contentId,SSPErrorCode.PartnerRestGetStream404);
}

将调试器附加到进程时,已将断点设置为if 语句或之前,当条件为false(responseMessage.StatusCode为OK)时,调试器进入if语句。然后,然后在不执行任何操作的情况下对throw语句进行步骤,然后继续执行代码。



我尝试过:



重新启动VS,注销我的Windows用户,重新启动,清理解决方案,重新构建它,重建它,回收应用程序池,重新启动IIS,在if语句和条件之内添加更多的代码 - 没有工作到目前为止。



必须有一个缓存,我可以清理掉,以摆脱它,但是什么,在哪里?



Googling我只找到http: - social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/d4b70fd7-b74a-42ce-a538-7185df3d3254/,所以我尝试手动设置断点,并没有在这个类中断,虽然同样的确在其他类中断了。



我很乐意解决这个问题,而无需重新安装VS。谢谢你提前!






更新


  1. 由于我把它放了,找不到答案,所以我继续关注我的项目。

  2. 我偶然发现了这个问题, John MacIntyre on 这篇文章,最后是一个简化的例子:




 使用系统; 

命名空间IEnumerableBug2
{
类程序
{
static void Main(string [] args)
{
if new object()== null)
throw new Exception();
try {} catch {}
}
}
}




更新#2



请注意,我的方法也有一个try-catch语句它在'if'语句之后的几行。



我刚刚尝试再次重现这个bug,失败了。我将为可能需要的其他人留下stackoverflow的问题,但正如我所写,我不再能够重现这种行为。

解决方案

我也遇到这个问题,但稍有不同。
这是我的代码:

  string lockCode = Guid.NewGuid()。ToString(); 
bool alreadyLocked = string.IsNullOrWhiteSpace(lockCode);

如果(已经锁定){
抛出新的异常(已经运行);
}

try {
PerformTask(task);
}
finally {
UnlockTask(task,lockCode);
}

如您所见,lockCode字符串始终分配一个Guid值。调试器进入if范围,尽管不应该。不要抛出异常。



我在Windows 7 64位上运行带有ReSharper 6.0的Visual Studio 2010 SP1。

  Microsoft Visual Studio 2010 
版本10.0.40219.1 SP1Rel
Microsoft .NET Framework
版本4.0.30319 SP1Rel
已安装版本:高级

这在我的框架4.0上使用了一个ASP.NET应用程序。
我尝试运行在我的机器上不同项目上发布的可重用代码,但无法重现此问题。



此外,我已经删除了Shadow Copy Cache对于这个路径上的.NET Framework:

  C:\Users\username\AppData\Local\assembly 

我删除了VS2010符号缓存目录和临时ASP.NET文件。
我重新启动了我的电脑,清理了整个解决方案并重建了一切。
不知道为什么会发生这种情况。



解决方法:如果我从方法中删除try-finally部分,或者提取将throw语句转换成不同的方法,调试器正确地跨越'if'范围。



抱歉,为了不发布真正的解决方案,我希望这有助于隔离问题或其周围的工作。


I'm using VS 2010 Professional (On Windows 7 Professional 64), writing with WCF 4.0. I have the following code:

        if (responseMessage.StatusCode == HttpStatusCode.NotFound)
        {                
            throw new ContentNotFoundException(contentId, SSPErrorCode.PartnerRestGetStream404);
        }

When attaching the debugger to the process, having set a breakpoint at the "if" statement or before that, while the condition is false (responseMessage.StatusCode is 'OK'), the debugger steps into the "if" statement. It then steps over the "throw" statement without doing anything, then continuing on with the code.

I've tried:

Restarting VS, logging out my Windows user, rebooting, cleaning the solution, building it again, rebuilding it, recycling the application pool, resarting IIS, adding more code inside the "if" statement and inside the condition - nothing worked so far.

There must be a cache somewhere which I can clean to get rid of it, but what, and where?

Googling this I only found http:--social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/d4b70fd7-b74a-42ce-a538-7185df3d3254/, so I tried manually setting the breakpoint, and it didn't break in this class, although the same did break in other classes.

I would love to fix this without reinstalling VS. Thank you in advance!


Update:

  1. Since I put this up and could not find an answer, I moved on with my project.
  2. I stumbled upon this issue, reported by John MacIntyre on this post, which ends up with a simplified example:

using System; 

namespace IEnumerableBug2 
{ 
    class Program 
    {
        static void Main(string[] args) 
        {
            if (new object() == null)
                throw new Exception();
            try { }  catch { }
        }
    }
}

Update #2:

Note that my Method also has a try-catch statement in it, a few lines after the 'if' statement.

I've just tried reproducing this bug again, and failed. I'm going to leave the question on stackoverflow for others who might need it, but, as I wrote, I am no longer able to reproduce the behaviour.

解决方案

I am experiencing this problem too, but slightly different. Here's my code:

        string lockCode = Guid.NewGuid().ToString();
        bool alreadyLocked = string.IsNullOrWhiteSpace(lockCode);

        if (alreadyLocked) {
            throw new Exception("already running");
        }

        try {
            PerformTask(task);
        }
        finally {
            UnlockTask(task, lockCode);
        }

As you can see, the lockCode string is always assigned with a Guid value. The debugger steps into the 'if' scope, although it shouldn't. The exception isn't thrown.

I am running Visual Studio 2010 SP1 on Windows 7 64-bit with ReSharper 6.0.

Microsoft Visual Studio 2010
Version 10.0.40219.1 SP1Rel
Microsoft .NET Framework
Version 4.0.30319 SP1Rel
Installed Version: Premium

This happens to me with an ASP.NET application on framework 4.0. I tried running the repro code posted here on a different project on my machine but could not reproduce the issue.

Also, I have deleted the Shadow Copy Cache for the .NET Framework on this path:

C:\Users\username\AppData\Local\assembly

I deleted the VS2010 symbols cache directory, and the Temporary ASP.NET Files. I restarted my computer, cleaned the whole solution and rebuilt everything. No clue why this happens.

Workaround: If I remove the 'try-finally' part from the method, or extract the throw statement to a different method, the debugger steps over the 'if' scope correctly.

Sorry for not posting a real solution to this, I hope this helps either isolate the problem or work around it.

这篇关于visual studio 2010调试器 - 步入“if”尽管条件虚假的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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