View parameter values while debugging with method call of many parameters? - c#

Let's say I'm degugging code and I reach a breakpoint where the line of code is something like this:
GetEmpInfo(empName, empLast, empSS, empDept, empBirth, empCity, empState,
empCountry, parm1, moreparms, evenmore, toomanyparms);
Is there a way to know what value each of those parameters has without going through each variable? I know there has to be a way; I just don't know where it is.
Thanks.

There are 7 good ways to do it -
1. Data Tip
2. Autos Window
3. Locals Window
4. Watch Window
5. Quick Watch Window
6. Parallel Watch Window
7. Immediate Window
Check this for more info

You can use the DebuggerDisplay Attribute
[DebuggerDisplay("{Param1} {Param1} {Param1}")]
And when you hover over the object you will see the values that are entered above

Related

Is there object/class browsing in Visual Studio with C# while debugging/code tracing?

So my idea is I want to see what an object's members or properties would return/change while I am debugging/tracing. There is Object Browser but it is only to show tree list of an object.
For example, let's say
var cacheDir = cotext.CacheDir;
But I want to change .CacheDir to .ExternalCacheDir while debugging to see what value would be returned to the variable.
var cacheDir = context.ExternalCacheDir;
Otherwise, I have to change it in editing mode and restart the whole debugging process. I think that we can do something like this in browser developer console or Jupyter notebook like CLI environment.
With C# Keyboard settings you press Ctrl+Alt+I - the immediate window. Or via the Command window type Immed.
In the Immediate Window you can do ad-hoc commands.
So in the debugger IDE you'd step over the line of code:
var cacheDir = cotext.CacheDir;
And now you want to tweak it just a once off, Ctrl+Alt+I
Then paste:
cacheDir = cotext.ExternalCacheDir;
And press enter. You can always revert back in the immediate window, eg:
cacheDir = cotext.CacheDir;
If you just want to see the value of a variable you can do a ? cacheDir to see the values. Give it a go :)
While you're debugging, you can use Watch windows to watch variables and expressions.
Open a Watch window by selecting Debug > Windows > Watch > Watch 1,
or pressing Ctrl+Alt+W > 1.
In the Watch window, select an empty row, and type variable or Expression
Continue debugging by selecting Debug > Step Into or pressing F11 as needed to advance.
The variable values in the Watch window change as you iterate through the for loop.
Reference
There are many ways to see variables values in VS. You can use the Watch Window, You can hover a variable and see a Data Tip, you can use the Immediate Window. You can also check OzCode that provides a HUD that shows the variable values without the need to open any Window, and provide a nice way to choose the properties that you like to present, and provides a google like search for variable name and values.
In the next version of OzCode (you can download a preview version of it) you can use OzCode Predict that also support VS Edit&Continue.

C# int.TryParse("3",out tst) AND Convert.ToInt32("3") returning 0x00000003 instead of 3 what can it be?

All my code works fine until i did some changes that i cant track right now.
when i debugg my code i can see that the converting returning hex instead of number.
I have no idea why its happening or what can cause this.
any ideas please?
Thanks.
It's a VS feature, You can disable it:
You're looking at the value in a debugger. Integer values are not stored "in hex" or even "in decimal". 3 is stored in binary, but viewed based on your debugger settings.
You can disable hexadecimal viewing by right clicking in the Watch or Immediate view and deselecting Hexadecimal Display.

find out if IWebBrowser2.ExecWB print was cancelled in C#

I am using internet explorer to print a html document like this in C#:
ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER,
2, null);
This works fine, but I would like to know if the used pressed print in the dialog or cancel.
Is it possble to get this information without a ugly window hook hack ? something like a certain out parameter ?
This is not possible. I had this problem and ended up testing all possible values for the last output parameter, the output parameter is not used for this command.

See return value in C#

Consider the following piece of code:
As you can see we are on line 28. Is there any way to see the return value of the function at this point, without letting the code return to the caller function?
Foo.Bar() is a function call which generates a unique path (for example). So it's NOT constant.
Entering ?Foo.Bar() in the immidiate window doesn't work either, since that reevaluates the code:
?Foo.Bar()
"80857466"
?Foo.Bar()
"2146375101"
?Foo.Bar()
"1106609407"
?Foo.Bar()
"792759112"
In VB.NET it's possible by entering the function's name in the Watch, which will then threat it as a variable.
But in C# this is not possible, any other tips?
PS: rewriting is not an option.
Answer found here: VS get returned value in C# code?
It is actually visible. Debug + Other
Windows + Registers. Look at the value
of EAX (RAX in x64). The value of
simple integral types are returned in
the EAX register. Long in EDX:EAX.
Floating point in STx (XMM00 in x64).
Assuming you are using visual studio, you could use the Immediate window. If you type Foo.Bar(); in the Immediate window you will get the result you are after, if you don't want it to re-evaluate stick a break point in the appropriate spot IE either before it evaluates the first time or in Foo.Bar() itself.

Debugging Help - set a value in debug mode?

I am debugging and I hit my break point. I hover over a variable and I get the standard drilldown. I see a Nullable prop and it is null. I right click and choose "edit value". No matter what I seem to type, I get "The value could not be set. Please check your entry."
I have tried 5/1/09, new DateTime(2009, 5, 1), {05/01/2009}... pretty much every flavor I could think of. What the heck am I doing wrong? I would like to code in the value and continue debugging with the new value.
Any suggestions?
Thanks, ~ck
DateTime.Parse("5/1/2009")
Seems easy to me. I had this line:
DateTime dt = DateTime.Parse("01/01/2000");
Hit the breakpoint, and typed this into the immediate window:
dt = DateTime.Parse("02/01/2010")
The same technique also works when editing the value in the debugger tooltip, the locals window, the autos window, the watch window and even the quick watch window.
Try using #5/1/2009#
In a Watch window line, type this in the name field:
dt = new DateTime(2009,5,1)
The line will be disabled so just delete it. In the next line, type in dt and it will be the value you want.
Is this object a "DateTime" or a "Nullable" (which is the same as "DateTime?")?

Categories

Resources