断章取义变量在Visual Studio 2010中的调试器 [英] Out Of Context Variables In Visual Studio 2010 Debugger

查看:257
本文介绍了断章取义变量在Visual Studio 2010中的调试器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有本地变量在Visual Studio 2010中的调试器一个C#控制台应用程序针对.NET 4.0是断章取义的一个非常奇怪的问题。我搜索过上的其他类似的问题,但在一些有相同的症状,似乎没有直接适用于这个问题(他们都似乎有其他的根本原因)。



问题是,对于一些变量(但不是全部),他们没有在本地窗口中出现我不明白他们的价值的工具提示,我也得到名XYZ并不在目前的情况下存在如果我把它们添加到Watch窗口。这似乎影响到一些变量,而不是其他的,我想不通的模式(它似乎并没有要依据成员与地方,与类结构或任何其他区别)。我重新启动我的电脑和Visual Studio,核实我在一个干净的调试版本,确信调试框架是正确的,就确定刷新观看屏幕​​上的变量,并试图各种法术和咒语。



我已经包含在 HTTP低于screenshoot(更大的版本://我。 stack.imgur.com/JTFBT.png )。



在这里输入的形象描述



有什么想法



编辑:



添加一些额外的信息:



问题是重复的。完全相同的变量工作或不工作,甚至在完全关闭并重新启动Visual Studio中。这使我相信居然有地方出了错,而不仅仅是内存损坏或什么东西系统化。



我还发现,这似乎是相关的try-catch块。如果我定位try语句外的断点,我可以看到任何的范围变量正常的。一旦执行点进入try语句try块之外的所有变量无法访问,我只能访问try语句里面的人。这几乎就像调试器是治疗try块作为一个单独的方法(虽然你可以看到代码/编译器仍然有机会获得在范围变量)。 ?有见过这种行为的人。



另一个编辑:



我(部分)收回我说过看来在任何封闭块中的代码调试展品这个奇怪的东西回吐这部分断章取义 - 在try-catch是犯罪嫌疑人。例如,如果我直接在屏幕截图设置一个断点在foreach语句中我可以看到在每次迭代的端口变量值,但没有foreach语句之外的变量(其中消失,只要我进入的foreach块) 。然后,一旦你进入try块,在端口变量突然消失。这是变得非常怪异。



此外,根据要求,整个方法的代码如下。

 私人无效ConfigureAnnouncerSockets(的XDocument configDocument)
{
的XElement socketsElement = configDocument.XPathSelectElement(/配置/网络/ AnnouncerSockets);
布尔useDefault = TRUE;
如果(socketsElement!= NULL)
{
//使用默认的播音员? (他们将在月底添加)
XAttribute defaultAttribute = socketsElement.Attribute(useDefault);
如果(!defaultAttribute = NULL)
{
useDefault = Convert.ToBoolean(defaultAttribute);
}

//获取默认频率
INT defaultFrequency = Announcer.DefaultFrequency;
XAttribute frequencyAttribute = socketsElement.Attribute(频率);
如果(frequencyAttribute!= NULL)
{
defaultFrequency = Convert.ToInt32(frequencyAttribute.Value);
}

//获取所有插座
的foreach(的XElement socketElement在socketsElement.XPathSelectElements(./插座))
{
//获取地址
ip地址地址= IPAddress.Broadcast;
串addressAttribute =(字符串)socketElement.Attribute(地址);
如果(的getAddress(addressAttribute,楼盘地址,真正的)!)
{
Intelliplex.Log.Warn(无效的播音员套接字地址:+ addressAttribute);
继续;
}

//获取本地地址
ip地址将localAddress = NULL;
串localAddressAttribute =(字符串)socketElement.Attribute(将localAddress);
如果(的getAddress(localAddressAttribute,楼盘将localAddress,假的)!)
{
Intelliplex.Log.Warn(无效的播音员套接字的本地地址:+ localAddressAttribute);
继续;
}

//获取端口
名单,LT; INT>端口=新的List< INT>();
的String []范围=((字符串)socketElement.Attribute(端口))斯普利特(新[] {','});
的foreach(在范围内串范围)
{
的String [] = portPair range.Split(新[] {' - '});
INT FIRSTPORT = Convert.ToInt32(portPair [0]);
INT lastPort = portPair.Length> 1? Convert.ToInt32(portPair [1]):FIRSTPORT;

{
ports.Add(FIRSTPORT);
},而(++ FIRSTPORT< = lastPort);
}

//获取本地端口
INT将localPort = socketElement.Attribute(将localPort)!= NULL
? Convert.ToInt32((字符串)socketElement.Attribute(将localPort)):0;

//获取频率
INT频率= socketElement.Attribute(频率)!= NULL
? Convert.ToInt32((字符串)socketElement.Attribute(频率)):defaultFrequency;

//创建插座(S),并将其添加/他们的经理
的foreach(港口INT端口)
{

{
IPEndPoint端点=新IPEndPoint(地址,端口);
IPEndPoint localEndPoint =将localAddress == NULL
?新IPEndPoint(IPAddress.Any,0):新IPEndPoint(将localAddress,将localPort);
播音员插座=新的播音员(频率,终端,localEndPoint);
AnnouncerSockets.Add(插座);
}
赶上(异常前)
{
Intelliplex.Log.Warn(不能添加播音员插口:+ ex.Message);
}
}
}
}

//添加默认的公告插座?
如果(useDefault)
{
ConfigureDefaultAnnouncerSockets();
}
}


解决方案

所以,事实证明,这是关系到PostSharp的错误。使用PostSharp我一直但是从我的代码删除了所有方面,并确保没有被应用。我也验证与反射的方法是在组装完好。然而,它的出现只是引用PostSharp触发某种导致此问题的调试符号的操纵。 A(略)的更多信息可以在这里找到:



http://www.sharpcrafters.com/forum/Topic5794-21-1.aspx#bm7927



此外,在发行说明最新PostSharp修补程序规定的修补程序2.1.5.6固定的问题之一是调试符号:在隐迭代器丢失局部变量符号



当我安装了最新的而最大的PostSharp问题消失了,宇宙恢复正常。希望这个问题/答案将帮助其他人使用PostSharp谁在下一次正式发布PostSharp在这之前奇怪的行为绊倒。请确保你在修补程序2.1.5.6或更高版本(给出错误的严重程度,这也许应该是一个实际的释放)。



感谢所有帮助每个人。


I am having a very odd problem with local variables being out of context in the Visual Studio 2010 debugger for a C# console application targeting .NET 4.0. I've searched for other similar questions on SO, but while some have the same symptoms, none seem to apply directly to this problem (they all appear to have other root causes).

The problem is that for some variables (but not all) I do not get a tooltip with their value, they do not appear in the Locals window, and I get "The name 'xyz' does not exist in the current context" if I add them to the Watch window. It appears to affect some variables but not others, and I can't figure out a pattern (it doesn't seem to be based on member vs. local, class vs. struct, or any other differentiator). I've restarted my computer and Visual Studio, verified I'm in a clean Debug build, made sure the debugging frame is correct, made sure to refresh the variables in the watch screen, and attempted various spells and incantations.

I've included a screenshoot below (bigger version at http://i.stack.imgur.com/JTFBT.png).

Any thoughts?

EDIT:

Adding some additional information:

The problem is repeatable. The exact same variables either work or don't work, even after completely shutting down and restarting Visual Studio. This leads me to believe there's actually something systematic going wrong rather than just memory corruption or something.

I've also discovered that it appears to be related to the try-catch block. If I position the breakpoint outside the try statement I can see any of the in-scope variables normally. As soon as the execution point enters the try statement all the variables outside the try block become inaccessible and I can only access the ones inside the try statement. It's almost as though the debugger is treating the try block as a separate method (though you can see the code/compiler still does have access to in-scope variables). Has anyone seen this behavior before?

ANOTHER EDIT:

I (partially) take back what I said about the try-catch being suspect - it appears that in this portion of the code the debugger exhibits this odd taking stuff out of context for any enclosing block. For example, if I set a breakpoint directly inside the foreach statement in the screenshot I can see the "port" variable value on each iteration, but none of the variables outside the foreach statement (which disappear as soon as I enter the foreach block). Then as soon as you enter the try block, the "port" variable suddenly goes away. This is getting really weird.

Also, as requested, the code for the entire method is below.

private void ConfigureAnnouncerSockets(XDocument configDocument)
{
    XElement socketsElement = configDocument.XPathSelectElement("/Configuration/Network/AnnouncerSockets");
    bool useDefault = true;
    if (socketsElement != null)
    {
        //Use the default announcers? (they will be added at the end)
        XAttribute defaultAttribute = socketsElement.Attribute("useDefault");
        if (defaultAttribute != null)
        {
            useDefault = Convert.ToBoolean(defaultAttribute);
        }

        //Get the default frequency
        int defaultFrequency = Announcer.DefaultFrequency;
        XAttribute frequencyAttribute = socketsElement.Attribute("frequency");
        if (frequencyAttribute != null)
        {
            defaultFrequency = Convert.ToInt32(frequencyAttribute.Value);
        }

        //Get all sockets
        foreach (XElement socketElement in socketsElement.XPathSelectElements("./Socket"))
        {
            //Get the address
            IPAddress address = IPAddress.Broadcast;
            string addressAttribute = (string)socketElement.Attribute("address");
            if(!GetAddress(addressAttribute, ref address, true))
            {
                Intelliplex.Log.Warn("Invalid announcer socket address: " + addressAttribute);
                continue;
            }

            //Get the local address
            IPAddress localAddress = null;
            string localAddressAttribute = (string)socketElement.Attribute("localAddress");
            if(!GetAddress(localAddressAttribute, ref localAddress, false))
            {
                Intelliplex.Log.Warn("Invalid announcer socket local address: " + localAddressAttribute);
                continue;
            }

            //Get the port(s)
            List<int> ports = new List<int>();
            string[] ranges = ((string)socketElement.Attribute("port")).Split(new[] { ',' });
            foreach (string range in ranges)
            {
                string[] portPair = range.Split(new[] { '-' });
                int firstPort = Convert.ToInt32(portPair[0]);
                int lastPort = portPair.Length > 1 ? Convert.ToInt32(portPair[1]) : firstPort;
                do
                {
                    ports.Add(firstPort);
                } while (++firstPort <= lastPort);
            }

            //Get the local port
            int localPort = socketElement.Attribute("localPort") != null
                ? Convert.ToInt32((string)socketElement.Attribute("localPort")) : 0;

            //Get the frequency
            int frequency = socketElement.Attribute("frequency") != null
                ? Convert.ToInt32((string)socketElement.Attribute("frequency")) : defaultFrequency;

            //Create the socket(s) and add it/them to the manager
            foreach (int port in ports)
            {
                try
                {
                    IPEndPoint endPoint = new IPEndPoint(address, port);
                    IPEndPoint localEndPoint = localAddress == null
                        ? new IPEndPoint(IPAddress.Any, 0) : new IPEndPoint(localAddress, localPort);
                    Announcer socket = new Announcer(frequency, endPoint, localEndPoint);
                    AnnouncerSockets.Add(socket);
                }
                catch (Exception ex)
                {
                    Intelliplex.Log.Warn("Could not add announcer socket: " + ex.Message);
                }
            }
        }
    }

    //Add default announcement sockets?
    if (useDefault)
    {
        ConfigureDefaultAnnouncerSockets();
    }
}

解决方案

So it turns out this is related to a bug in PostSharp. I had been using PostSharp but removed all aspects from my code and ensured that none were applied. I also verified with Reflector that the methods were intact in the assembly. However, it appears simply referencing PostSharp triggers some kind of manipulation of the debugging symbols that causes this problem. A (little) more information can be found here:

http://www.sharpcrafters.com/forum/Topic5794-21-1.aspx#bm7927

Also, in the release notes for the latest PostSharp hotfix states one of the fixed issues in hotfix 2.1.5.6 is "Debugging symbols: local variable symbols lost in implicit iterators."

When I installed the latest and greatest PostSharp the problem went away and the universe returned to normal. Hopefully this question/answer will help anyone else using PostSharp who stumbles on this odd behavior before the next official PostSharp release. Make sure you're on hotfix 2.1.5.6 or greater (given the severity of the bug, this probably should have been an actual release).

Thanks for all the help everyone.

这篇关于断章取义变量在Visual Studio 2010中的调试器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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