Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS2015 Debugger showing wrong values?

EDIT: When I run this code in Visual Studio 2013, the debugger is showing Utc, not Local. It's a bug in Visual Studio 2015 Debugger.

EDIT: Have taken the code and put in stand-alone console app, but cannot reproduce in either version of VS. Bummer.

Can someone explain to me how what you see in this screenshot is possible?!

  1. On line 298, endingTimePeriodStartDate is redefined as its Date value but set to DateTimeKind.Utc.
  2. On Line 300, if endingTimePeriodStartDate is not actually DateTimeKind.Utc, an exception is thrown.
  3. The debugger breakpoint on line 305 is hit, meaning the exception on line 302 was not thrown, meaning endingTimePeriodStartDate.Kind == DateTimeKind.Utc
  4. (I also did a System.Diagnostic.Debug.WriteLine(endingTimePeriodStartDate.Kind) before line 305 and it prints “Utc” in the Output window).
  5. When I look at endingTimePeriodStartDate in the Locals and Watch debugger windows, and when I mouse hover over the variable, the Kind property shows DateTimeKind.Local

enter image description here

like image 764
core Avatar asked Oct 02 '15 13:10

core


1 Answers

Usually the debugger will show wrong line numbers, and go into old code if it is running a different version of the dll (a former version) than the one that your code is showing. This happens

  • when there is some kind of caching
  • when the former running version wasn't closed correctly, or is still running in another process.
  • when the Visual Studio is not pointing to the correct code

Usually to fix this, you should:

(Start by trying only a "clean" and "rebuild")

  1. Stop all running or debugging Visual Studio projects.
  2. Close all your Visual Studio solutions and windows, so that Visual Studio is not running.
  3. (If next step doesn't do the trick, then the next time around reboot your computer as well before going on to next step)
  4. Re-open only the solution you need to run. Hit "Clean solution". Then "Rebuild solution".

Check if this fixed the problem.

  1. Manually delete the bin folders: (if the clean/rebuild didn't work)

5.1 If your afraid, backup your whole source directory. After everything works, delete the backup...

5.2 manually go into the dependent projects (that are referenced in your "wrong code showing" project) and in each one of them, go into the obj and into the bin folder and delete everything that was automatically created from there - in other words, everything that you did not put there manually. Usually that's everything. Don't worry, visual studio will re-create the Debug and Release directories and fill them up.

Delete the obj and bin of your project as well.

Rebuild everything.

like image 131
pashute Avatar answered Oct 15 '22 15:10

pashute