简体   繁体   中英

DateTime format in Visual Studio 2019 Locals and Autos Windows

Insane problem: Any variable that is a System.DateTime will not show me anything useful in the Locals window. They all show the same value:

Example: var now = DateTime.Now;

In the Autos or Locals window, now will show this value: Date = {Date = {Date = {Date = {Date = {Date = {Date = {Date = {Date = {Date = {<Evaluation of DebuggerDisplay attribute reached max recursion count>}}}}}}}}}}

This is for Local dates, UTC dates, asp.net core, .Net 4.7.2, whatever dev I'm doing, it's the same problem. I can't imagine this is by design, and never had this problem in prior versions. I can't find any settings to change this. Does anyone know how to restore the value in the Locals window to a simple "{3/21/2020 8:54:23 PM}" format?

Ok figured this out, thanks to help from Oguz. I started down the path described in https://developercommunity.visualstudio.com/content/problem/802367/datetimenow-cannot-provide-the-value-host-value-no.html and when I went to drop my shiny new dll in the specified path (C:\\Users\\%username%\\Documents\\Visual Studio 2019\\Visualizers), I found a file named ObjectFavorites.json, with this content:

{
  "$schema": "https://aka.ms/vs/debugger-managed-favorites-schema",
  "types": {
    "System.DateTime": {
      "favorites": [
        "Date"
      ]
    }
  }
}

I don't know where that came from, but deleting the file instantly fixed the problem. The debugging windows are back to normal, and I didn't even have to drop in that silly dll file.

Does anyone know how to restore the value in the Locals window to a simple "{3/21/2020 8:54:23 PM}" format?

This is quite a strange behavior in VS2019.

In my side, I create a net framework 4.7.2 project, add var now = DateTime.Now; in code editor and then step into it, it shows the right time successfully as you wished.

在此处输入图片说明

So please try these suggestions to troubleshoot your issue:

  1. delete any component caches under C:\\Users\\xxxx\\AppData\\Local\\Microsoft\\VisualStudio\\16.0_xxxx\\ComponentModelCache

  2. use devenv /safemode to start your VS Instance or disable any third party extensions under Manage Extensions menu to test whether it is caused by any third party extensions.

  3. do a fix in visual studio

In addition , if your VS is not the latest version, please update it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM