13

I'm using VS 2015 Update 2 with an asp.net 5 web project configured for debug mode. When I run the project with F5 to debug it and hit a break point, some variables can not be observed in the watch window even when they are in scope. Further, if I hover over such variables no value is displayed.

If I use the same visual studio to create an empty web project and add a webform and place the code in the load method, the debugger works fine. That is to say, I can see the variables in the watch window and I can see their values by hovering over them. I glean from this that the root cause of the issue is not VS2015 Update 2 but rather something to do with the project or solution configuration, perhaps specific to asp.net 5 web projects.

I've scoured the web for answers and similar problems happen when trying to debug compiler optimized code. But I am running the solution in debug mode. Any suggestions?

Screenshot of error

I am aware of Variable does not exist in the current context while debugging but it applies to a different version of visual studio and the solutions offered there do not fix my issue.

Community
  • 1
  • 1
RonC
  • 31,330
  • 19
  • 94
  • 139
  • Looks like it's optimized away because `list` is local in scope and you never use it after `DoSomething()` returns, so there's no point in having it. Do something with `list` before `i++` and see if that changes anything. (A simple messagebox showing one of the elements in `list` will work.) – Ken White Apr 06 '16 at 22:17
  • Ken White - I agree, it's being optimized away. The question is why and how do I get the compiler to not optimize it away...I am in debug mode after all? – RonC Apr 07 '16 at 14:16
  • I'm having the same problem since Update 2! – Dave New Apr 08 '16 at 11:08

2 Answers2

11

I had the same problem. Eventually I noticed that some settings are different after update 2.

You need to go to Tools --> Options --> Debugging --> General and then check "Use Managed Compatibility Mode".

That worked for me.

Danny van der Kraan
  • 5,344
  • 6
  • 31
  • 41
  • 1
    Danny, thank you for this answer. I can confirm that this is one way to fix my problem, but it does so by using the legacy debug engine rather than by fixing the configuration of the modern debug engine. Also, this answer doesn't explain why the same code debugged in two different project types with the same visual studio behaves differently regarding whether the variables exists in the debugger. For these reasons I have chosen not to accept this answer yet and am waiting to see if someone else has a better solution. Still, I appreciate your answer. – RonC Apr 07 '16 at 13:24
  • Agreed. The patch is much better. :) – Danny van der Kraan Apr 18 '16 at 08:55
  • Worked for me ( vs2015) – Royi Namir Dec 07 '16 at 14:02
7

This is a bug that was introduced in Visual Studio 2015 Update 2. Essentially the debugger is unable to inspect local variables in dynamic modules. We released a hotfix for it today. You can download the patch here. Documentation for the patch is here. Let me know if the patch does not fix your particular scenario.

Thanks!

-Patrick Nelson

Patrick Nelson - MSFT
  • 3,182
  • 1
  • 14
  • 13
  • Thank you so much for your help. Sadly though, this patch did not resolve my issue. I installed the patch and ran my same test and I still get a message that the variable does not exist in the current context and when I hover the vars while debugging no value is displayed for them. I then tried uninstalling the patch and reinstalling it and restarting the computer, but still the patch seems to have no affect for me. – RonC Apr 11 '16 at 20:56
  • Can you share a project so I can investigate? – Patrick Nelson - MSFT Apr 11 '16 at 21:36
  • I would be happy to. What's the easiest way to get I to you? – RonC Apr 11 '16 at 21:48
  • The hotfix must have been updated last night based on my feedback. When I run the hotfix installer again today the screens are a bit different and the hotfix installed now resolves my issue. Thank you! I love the new open Microsoft, you all are responsive and awesome! – RonC Apr 12 '16 at 16:09
  • I can't use this patch, since it says "requires a member of the visual studio 2015 family to be present", which makes no sense since that is exactly the product I have installed. At this point Visual Studio is completely useless for debugging. Nothing I've tried works, including the "Use Managed Compatibility Mode". – Smack Jack Jun 03 '16 at 03:40
  • @SmackJack if using Managed Compatibility Mode doesn't fix it, then the patch won't help. Sounds like you are running into a different issue. Please open a connect bug at http://connect.microsoft.com/VisualStudio and we can take a look. – Patrick Nelson - MSFT Jun 03 '16 at 16:37
  • @PatrickNelson-MSFT, I have the same issue under Visual Studio 2019 Professional (Version 16.8.4), did you solve it ? – webpat Jan 23 '21 at 09:58