In Visual Studio 2013, how can I dump the contents of a variable to a file while debugging?

I have a variable of type List that is returned from an Entity Framework call and a bunch of other processing before being dumped into a variable that is then serialized to JSON, etc. etc.

It would be really handy if I could extract data from each one available along the way to analyze where things are going wrong (or right to this mater)

For variables with little data, the immediate window is fine, but the variable I'm currently playing in has over 1000 rows of data that would be much easier to filter if I could get it into a spreadsheet or the like.

I would rather not port my code using Console.WriteLines or another Trace if I can help it.

So, is there some trick or extension, or just some code that I can enter into the direct or command window, do this?

I think this may be the way, but it is not really for me.

data.ForEach(Console.WriteLine); 

      

or

File.WriteAllLines("C:\temp", data);

      

Link to Immediate Window

EDIT

Here are some examples of what doesn't work

    [Test]
    public void ImmediateWindowTest()
    {
        var data = new List<dynamic> { new { Z = "A", Y = 1 }, new { Z = "B", Y = 2 } };

        // System.IO.File.WriteAllText (@"c:\temp\foo.txt", data);  
        // -- The best overloaded method match for 'System.IO.File.WriteAllText(string, string)' has some invalid arguments

        // System.IO.File.WriteAllLines(@"c:\temp\foo.txt", data); 
        // -- The best overloaded method match for 'System.IO.File.WriteAllLines(string, string[])' has some invalid arguments

        // System.IO.File.WriteAllLines(@"c:\temp\foo.txt", data.Select(p=>String.Format("{0}, {1}", p.Z, p.Y)); 
        // -- Expression cannot contain lambda expressions

    }

      

+3


source to share


2 answers


I just tried the Immediate window and it works, giving you write permission to the output directory. Therefore, if your code is:

var a = "Lawrence\r\nLessig";

      

Then in the immediate window use:



File.WriteAllText (@"c:\Users\MyUserLogin\documents\foo.txt", a);

      

Creates a file foo.txt containing:

Lawrence
Lessig

      

+3


source


I am working on a commercial version of Visual Studio that can help you achieve what you need to do:



If you need to filter the list, you can use OzCode Filter . If you want to perform text search on field values, you can use OzCode Search. If you just want to export the object graph to a file that is not yet directly supported, but after doing Search, you will find a JSON file in the% TEMP% \ OzCode section that will contain all the data (down to the depth in the object graph you found).

0


source







All Articles