Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To export an object while debugging in Visual Studio 2019, follow these steps:

  1. Add a breakpoint where you want to export the object.
  2. Run the program in debug mode and hit the breakpoint.
  3. Open the Immediate window by going to Debug > Windows > Immediate.
  4. Type the following command in the Immediate window: >? System.IO.File.WriteAllText(@"C:\path\to\file.txt", Newtonsoft.Json.JsonConvert.SerializeObject(object)); Replace "C:\path\to\file.txt" with the desired file path and name, and "object" with the name of the object you want to export.
  5. Press Enter to execute the command. The object will be serialized to JSON and saved to the specified file location.

Note: This method requires the Newtonsoft.Json package to be installed in the project. You can add it to your project by going to Tools > NuGet Package Manager > Manage NuGet Packages for Solution and searching for "Newtonsoft.Json".