Visual Studio extension to dump object to file during debug? - visual-studio

I'm debugging something (in Visual Studio 2017 and 2019) where, somewhere, a number's changing between an old version of code and a new version. It'd be useful to be able to recursively dump the values of fields in an object from the debugger for comparison. Especially where the dump is large and can be run through diff rather than compared by eye. Ozcode looked promising, but the trial is doing nothing. I suspect Ozcode only works for C#/.NET apps and I'm in C++ native.
I can navigate manually through the objects in the debugger and explore all the field values so clearly VS has access. I can query the values of the fields in the top level of an object in the Immediate Window by typing something of the form
?MyObject
I've seen mention of the possibility of running a loop in the Immediate Window- doesn't work here. Nor does using other suggestions of commands to dump to JSON using .NET assemblies, because I'm not in .NET
Using the Package Manager Console as a hacky way in, I can run PowerShell scripts that get at the debugger and iteratively dump fields to text to as deep a level as I want. It's easier than adding exploratory code and the scripts can be created and run while stopped at a breakpoint which makes it easier to explore what's going on, but it'd be so much easier if there were an extension adding a dump option to the context menu of an object in the debugger. I don't see anything obvious when searching. Does anyone know of such a thing?

Related

creating a save point when debugging in visual studio

I have an error which is occurring only very late in my code (after it's been running for ~20 minutes) and so trying to pinpoint exactly where it is is tricky because I have a lot of recursive function calls and if I go too far the important variable values may have been changed. Is there a way I can set a kind of save point where all the variables have their values saved and which I can jump back to after I've done some exploring rather than having the run the whole thing again from the beginning?
I found this and just wanted to point out that Roger Lipscombe's comment is what I was also looking for:
Precisely: IntelliTrace https://learn.microsoft.com/en-us/visualstudio/debugger/intellitrace?view=vs-2022
and
Historical Debugging (which is part of IntelliTrace) https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2015/debugger/historical-debugging?view=vs-2015&redirectedfrom=MSDN
Only available on the enterprise version of Visual Studio
I have a workaround for this kind of issue: Using the Data Breakpoint, at least, it could output and save the value manually, and it also can help you check that what value was applied to your code line, I just get this idea from this case I met before:
Visual Studio. Debug. How to save to a file all the values a variable has had during the duration of a run?
If IntelliTrace tool is helpful for you like Roger Lipscombe's suggestion, one idea is that you could use IntelliTrace Standalone Collector tool without the VS in one machine:
https://msdn.microsoft.com/en-us/library/hh398365.aspx

Immediate Window in Design Mode

According to Microsoft: "The Immediate window is used at design time to debug and evaluate expressions, execute statements, print variable values, and so forth."
Notice it says "at design time". I have read other statements on the web to this effect as well.
However, when anybody asks why they get the "The expression cannot be evaluated while in design mode." error, everybody always states that it only works in debug mode.
I can understand some things will not work in design mode when they reference items like textbox box values. But I really don't understand why I have to set a breakpoint, run my application, and wait for it to get to the breakpoint, just to find out what 1 + 1 is.
I admit to frustration as I'm coming from Visual Basic 6.0. There I can print 1 + 1 and get 2 while in design mode. I can also call public functions and get answers while in design mode.
All of this comes from my looking for answers to type converting. Since I couldn't find an answer on the web, I decided the quickest and easiest way was to just test some statements REAL QUICK in the immediate window to see which one worked.
Is .NET a step backwards when using the immediate window?
I understand your frustration. Fortunately the development of Roslyn (Microsoft's open source C# compiler) allowed to have a so called "Interactive Windows" in Visual Studio. You need to install Roslyn, and after some easy setup steps you can evaluate C# expressions in that window:
https://github.com/dotnet/roslyn/wiki/Interactive-Window
It's very different from Immediate Window since REPL loop can be somewhat isolated, but it seems like that you can even interact with your project to some extent: Can the C# interactive window interact with my code?
This dates back even to 2011-2012, and it's default part of Visual Studio 2015 CTP1 since the end of 2015: View -> Other Windows -> C# Interactive
In short, it depends on the context of your application, that is, which solution you currently have selected in the Solution Explorer and its project type. e.g. Web Projects, will not evaluate immediate expressions at design time because it needs to setup that environment, however, library and console type projects will.
MSDN states:
"When establishing the context for design time expression evaluation,
Visual Studio references the currently selected project in Solution
Explorer. If no project is selected in Solution Explorer, Visual
Studio attempts to evaluate the function against the startup project.
If the function cannot be evaluated in the current context, you will
receive an error message. If you are attempting to evaluate a function
in a project that is not the startup project for the solution and you
receive an error, try selecting the project in Solution Explorer and
attempt the evaluation again."
However, if you are in a web project you will need to hit a breakpoint in order evaluate expressions in the Immediate Window.
This may be covered in other answers
To me, I can do whatever you mentioned in the immediate window in Visual Studio 2008, like finding out the sum of 1+1 or finding out the length of "sdfd". Length, etc. can be done from the immediate window. So it's not a step backward in .NET.

Using Statement removed when I save the project

I am new to C# and Enterprise Library and I ran into some weird behavior in the IDE that I was able to resolve, but I thought that it was strange enough that I wanted to get the reaction of other developers and perhaps benefit others.
I wanted to start out by using the Data Access blocks. Using VS2010 and NuGet, NuGet downloaded the data Access DLLS and set the references. However, every time I trued to type the following:
using Microsoft.Practices.EnterpriseLibrary.Data;
and then save the project, the line simply disappeared and then I would get a compile error suggesting that I was missing a reference when I tried to enter the following statement:
Database db = DatabaseFactory.CreateDatabase();
It didn't help when I tried to bypass the "using" statement by fully qualifying the object.
Finally, I resolved the issue by compiling using the full 4.0 Framework instead of the Client Framework.
My Visual Studio Environment is a bit screwed up, but so far the issue seems isolated to SSIS and SSRS. Is this behavior that others have experienced or is it my computer? It sure seems like unusual behavior to me.
This is not standard VS behaviour. Do you have the VS Power Commands installed? That has an option to remove unused usings on save.
On the Tools menu choose Options and scroll the left window, looking for PowerCommands. If it's there click that entry and then ensure Remove and sort usings on save is unchecked.
If you don't have that plugin installed it will be another plugin doing this.

What features of Visual Studio have you ignored that turned out to be very useful?

Bookmarks: In VS 5 they seemed like a great idea but I ended up not using them mainly because they didn't persist between sessions. E.g. If you closed a file that contained bookmarks they would not be there the next time you opened the file. You also could not move between bookmarks in different files etc. and I stopped using the feature.
For years I would kill the bookmarks toolbar whenever I installed VS. It took me years of using VS 2005 until I noticed that the bookmarks feature had actually been greatly enhanced and I use them on a daily basis.
Have you ignored Visual Studio features and later discovered their value?
It wasn't so much ignoring VS features as it was being ignorant of them, but for a while I didn't use custom project/item templates and code snippets, even though there was significant boiler plate code at my last job that was easily fixed by using these. I used the default templates for a while until I realized I could customize them for our application, and it's saved me loads of time since then. Code snippets I used to a lesser extent, but I do find them useful for smaller bits of code.
The other "feature" I find infinitely useful these days is "Delete all breakpoints" (CTRL-Shift-F9). I used to keep all of my breakpoints around, and they would persist in each solution...but it would 1) slow down VS load times, and 2) disrupt my debugging behavior by breakpointing in sections of code that I didn't need to breakpoint in anymore. Instead of manually removing them, I got into the habit of removing all of them, and then placing a few key ones around code I really needed to test. This was more contextual though - initially having a ton of breakpoints was useful to learn the codebase, but once I was familiar with it, isolating bugs was a lot easier without all of the breakpoints hanging around.
Macros for repetive keystrokes
The code palate (part of the toolbox) for storing my fave code clips
T4 toolkit for generating code
Customize the top toolbars to remove stupid shortcuts (like copy/cut/paste, undo/redo) and add ones I ALWAYS use (comment/uncomment block, step into/over/out)

Recommended .NET app installer?

I need to create an install for my app that executes the following actions:
Copies files
Writes registry settings
Registers a windows service
Writes an XML app.config file (based on user supplied info during install--a connection string)
Executes SQL scripts against a remote database (connection info obtained in #4)
Installs and registers a COM dll
Adds entry to Control Panel>Add/Remove programs for uninstall
I don't need any fancy logic to allow the user to customize these steps--I can hard-code them with user-supplied info injected where appropriate.
I looked at Wix but found the documentation and examples don't line up well with recent releases.
I also looked at NSIS but found support for writing XML to be too limited (the plugin for this can only handle strings up to 64 bytes).
I initially brushed off the VS2005 built in Setup project as incapable of handling these tasks but I'm ready to reconsider after stumbling with what I thought were better options.
Any suggestions?
I would still recommend looking into WiX a bit more. We use it to do everything but #6 on that list and while there is a small learning curve. We've been using WiX v3 for almost 3 years, and I haven't found too many places where the docs/tutorial is that far out of place. And usually where it is its because they cleaned up the syntax and made it better.
Also, as of the next release of Visual Studio (2010/Rosario) WiX is being build directly into Visual Studio, I'm not sure if in parallel with the current Setup Projects or replacing them completely.
A Visual Studio Installer project can do whatever custom code you want; wouldn't see why any of your requirements would be a problem.
I have used Visual Studio (2005) and Wise and can recommend both. You didn't mention if the tool had to be free, and if so that rules out Wise. Nevertheless Wise has a dead easy learning curve and is very powerful and well documented. I have had a few weird things happen to me with Visual Studio. One time I had to delete my project and start over (possibly due to stupidity on my part - never figured it out), but overall I have been using it for a couple years at my current job and it works for me.
You can use just Visual Studio and Windows without commercial tools to achieve what you need.
First, check out the answer to create a single installer file.
Then, you can research how to create a Custom Action class that can perform registry, read/write files and register COM dll's separately.

Resources