Exporting Objects from the Visual Studio Debugger

I had been searching for a way to export objects from my debugging windows (ex. locals, autos, watch) to their C# object initialization code for creating unit tests. There have been a few cases where there are some complex objects that I load through a database which would make great unit tests. Unfortunately i was not able to find anything like that, so I decided to create it myself. Enter Object Exporter.


Object Exporter is accessed through the tools menu and is only visible when you are debugging.

Export Objects (Tool Menu)

Once selected a dialog is shown with settings for the Object Export.

Export Objects (Select Objects)

The Output Format details which format you want your exported objects to be in. Maximum Object Depth refers to the maximum depth the Serializer will generate text for, this is important as some objects can have an infinite depth. Once you select a debugging window from the drop down, it’s objects will be loaded onto the screen and you may check the objects you wish to export.

The objects which can be selected correspond to the objects that exist within the various windows:

Export Objects (Locals)

Once the objects are selected and the “Export” button is selected, another dialog with the generated texts appear:

Export Objects (Xml Generated)

Export Objects (Json Generated)

Export Objects (CSharp Generated)

You can copy the text in the currently selected tab by selecting “Copy To Clipboard” or you can save all the objects to a folder by selecting the “Save All to Folder” button, a file per tab will be generated.

That’s pretty much it.


Omar Elabd

Omar Elabd

Omar Elabd is a software developer specializing within the .NET Framework. He has experience in developing Web and Desktop based applications using ASP.NET, MVC, WebAPI and WPF.
Omar Elabd
  • http://david.gardiner.net.au/ David Gardiner

    Hi Omar,
    what great timing! Only a few days ago I was looking at doing something very similar, except as a Debugger Visualizer, and only for DataTable objects.
    I’ll give your extension a try out. Do you have a github repo?

    • http://www.omarelabd.net/ Omar Elabd

      Hi David, I’ll probably add everything to github either tonight or tomorrow. I’ll shoot you a message (and update this post) with a link to the repo. What were you planning on doing with datatables?

      • http://david.gardiner.net.au/ David Gardiner

        That would be great.

        Actually I think you have a bug with the current VSIX. I tested out the extension but it’s crashing VS2013.

        I fired up a debugging instance of VS2013 and got the following (more informative) error:

        System.IO.FileNotFoundException was unhandled
        Message: An unhandled exception of type ‘System.IO.FileNotFoundException’ occurred in ObjectExporter.VsPackage.dll
        Additional information: Could not load file or assembly ‘Telerik.WinControls.RichTextEditor, Version=2014.3.1202.40, Culture=neutral, PublicKeyToken=5bb2a467cbec794e’ or one of its dependencies. The system cannot find the file specified.

        I’m guessing you forgot to include the Telerik assembly in the VSIX?

        • http://www.omarelabd.net/ Omar Elabd

          Good catch, the machines I used to test it out probably had all the telerik assemblies registered in the GAC. I just pushed out a new version, I Haven’t had a chance to test it on a machine without the assemblies but it should work. If your going to give it another shot let me know?

          • http://david.gardiner.net.au/ David Gardiner

            Getting closer!

            An unhandled exception of type ‘System.IO.FileNotFoundException’ occurred in Telerik.WinControls.RichTextEditor.dll

            Additional information: Could not load file or assembly ‘TelerikCommon, Version=2014.3.1202.40, Culture=neutral, PublicKeyToken=5bb2a467cbec794e’ or one of its dependencies. The system cannot find the file specified.

          • http://www.omarelabd.net/ Omar Elabd

            I spun up a fresh instance of VS2015 and gave it a shot, looks like everything should be in order now. Thanks for letting me know. Much appreciated! You should be able to get the latest update now.

          • http://david.gardiner.net.au/ David Gardiner

            Bingo! All good now.

            thanks :-)

          • Adam DeRuwe

            I’m still having issues with Visual Studio 2013. I just downloaded it from VS Gallery. Doesn’t seem to like very complex objects. When clicking export, VS completely hangs.

          • http://www.omarelabd.net/ Omar Elabd

            Some sort of a progress bar is coming up very soon, just curious how did the result look like?

          • Adam DeRuwe

            Here’s the output:


  • Yura Dubenskyy

    Does this solution handle objects with private/internal constructors?

    • http://www.omarelabd.net/ Omar Elabd

      I think I might be confused at your question but C# doesn’t allow for object instances with private constructors. Did you mean initializing it’s static fields? Object Exporter currently only uses Object and Collection initializes to generate your object, it provides a great starting point in terms of the C# it generates but it won’t always be perfect/compilable. Could you send an example for me to look at?

  • cedric perriot


    I am getting problem to make it work with VS2012. If i installed it from the addin manager it is asking for MPF12. If I alter the manifest of the vsix I am able to install it but it is not running because it is looking for Microsoft.VisualStudio.Shell.12.0 which I do not have.

    is it supposed to work with VS2012 ?

    • http://www.omarelabd.net/ Omar Elabd

      Hey Cedric, thanks for posting and letting me know. Let me look into the issue today and hopefully I’ll have a build out in about a day or two with a working 2012.

      • http://www.omarelabd.net/ Omar Elabd

        Working as of version 0.93. If you like it the addin please be sure to rate it on the visualstudiogallery.

    • http://www.omarelabd.net/ Omar Elabd

      Working as of version 0.93. If you like it the plugin please be sure to rate it on the visual studio gallery.

  • Darryl

    I’ve installed it but the menu item is not showing when I’m debugging. The extension manager shows that it is installed (happening for both vs2012 and vs2013(

    • http://www.omarelabd.net/ Omar Elabd

      Hey Daryl, you need to be stopped at a breakpoint for the menu option to appear. Let me know if that helps

      • Darryl

        Yeah I was stopped. Still not showing. It works on my work machine. So I wonder if there is some extension on my home machine that is interfering with it. But I can’t see any thing in the logs (I tried devenv /log) to suggest anything. I’m really keen on getting this working.

        • http://www.omarelabd.net/ Omar Elabd

          Hmm, i’m not sure what’s really going on. I’ll try and release a build tonight with better error reporting and that might help me track down the issue. We’ll get the issue fixed.

  • http://dirkwatkins.net/ dirq

    Awesome tool!

    Anyway to export a System.Collections.Hashtable? I have a bunch of collections on object, but the exporter always has them blank.

    • http://www.omarelabd.net/ Omar Elabd

      I’ll look into it, thanks for posting the issue on GitHub

  • http://mikael.palmstedt.com PalMik


    thanks for creating what seems to be a very practical and needed tool.

    I’m using VS 2015 Community and I have a problem with most of my objects that the Object exporter doesn’t seem to be able to access the content. E.g. I select a fairly complex object and it shows just (depth = 0) and when exporting it only initializes the empty object.

    Any ideas if this is a known issue?

    • http://www.omarelabd.net/ Omar Elabd

      Haven’t heard of any issues like this before, if there is a recursion somewhere you should get a depth of “>25” (this is configurable in the settings page). There hasn’t been a whole lot of VS2015 testing (only to validate basic functionality). Are you able to reproduce the same issue in 2013 with the same solution file? If you can share you solution, i’d be happy to take a look at it. Also i’d recommend you open an issue in Github (https://github.com/OmarElabd/ObjectExporter/issues) and add as much information as you can. Glad you enjoy the tool and sorry for the issues you are facing.

  • Taran James

    Hi Mate,
    This tool looks excellent and I would love to be able to use it unfortunately, we are still using Visual Studio 10 at work. Does anyone have version of this code that still works with VS10 as it used to be supported? Happy to reassmble from source code provided tell me how to do it.
    Thanks very much

    • http://www.omarelabd.net/ Omar Elabd

      Hi Taran, unfortunately support for 2010 was discontinued because I moved to .NET 4.5 and that’s not supported by 2010. I’m thinking of getting object exporter to a stable state then perhaps doing a port to 2010 and have that be a final version for 2010. However this would be a low priority and a few months down the line. The project is open source and is available at https://github.com/OmarElabd/ObjectExporter. If you did want to convert it you’d need to change any .NET 4.5 code to .NET 4 which is mostly async/await to something like a background worker. If you’d like I can take a look for the old .vsix file and give that to you, although it’s far from the current version and fairly buggy. The best solution might be to wait or try to attempt to convert it yourself.

      • Taran James

        If you could manage to find and old version that would be great. What I am trying to do with it is get values from 2 dimensional lists.
        Happy to deal with any bugs.
        Thanks again

        • http://www.omarelabd.net/ Omar Elabd

          Sure, i’ll take a look this evening.

          • Vittorio Sozzi

            Hi, have you found any old version that works on VS2010? Unfortunately I’ve trouble migrating my solution to a more recent Visual Studio :(
            Thank you!

      • user1

        I’m interested in the old version for 2010 too. Any chances for sharing it?

  • Brian Herbert

    Oh yes, that’s awesome!

    • http://www.omarelabd.net/ Omar Elabd

      Hey Brian, thanks for the comment. It’s true, there are cases where you may not get perfect code, and i’m working on improving that. But hopefully with what it generates it gets you closer to the goal you’re trying to accomplish, whether that’s unit testing or object inspection. Glad you like the tool!

  • Leszek Pietrzak

    Thanks for this extension, God bless you!
    Can you add an option/another extension(?) that will generate code for a class with dumped data for all public properties?
    class Person{
    public string Name {get;set;}
    private int Age;
    public DateTime Dob {get;set;}
    public int Children{get;set;}

    that will generate code like:
    var person = new Person{
    Name = “Some name”,
    Dob = DateTime.Now,
    Children = 1234

    That could help a lot with tests.

  • Martin Bartek

    I love this application. Unfortunatelly most of our classes are not accessible. It would be great if the app was able to create also mockups for NSubstitute or FakeItEasy. Ive downloaded the code and trying to modify the CSharp generator, but this looks like it is above my skills.

  • Alexander

    At first it was thinking a while, writing “Calculating…”.
    Then, when I have tried to make things simpler, and to add just one property of the object, my VS crashed. Removed – once and forever :(

  • mtrudel337

    Hi all
    I was pleased when I first saw the top of the export for a datatable.
    Unfortunately, 95% of the export is about the culture.
    The remaining 5% is only a few properties of the datatable.
    I tried exporting private but after 15 min it was still working. Had to kill.
    Any chance it may ALL properties (except rows. Dont need the data)
    I need to compare a datatable created by creating the table from scratch vs a datatable loaded from a Table2.Copy().

  • Furo Tamas Mark

    Hey Omar, awesome tool!
    You should take a look over at Github, there are a few Pull Requests that would be helpful for a lot of developers.