Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#: VS 2008 debugger executing property code

I have the following 2 lines of code:

lstvbWerteC.Clear ();
if (...)

lstvbWerteC is a field of List<T> with class scope. If in the VS 2008 debugger I set a breakpoint on the if statement I would expect lstvbWerteC.Count to be 0, but instead it is 1. My class has some properties that indeed fill the list. To prevent side effects in the debugger all the properties have the attribute [DebuggerBrowsable (DebuggerBrowsableState.Never)]. Nevertheless as soon as the locals window is visible the debugger seems to execute the code filling the list. With the locals window hidden the list is always empty reaching the if-breakpoint. Any information on debugger details concerning this type of problem would be appreciated.

like image 316
BExner Avatar asked Apr 10 '13 12:04

BExner


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.


2 Answers

Visual Studio menu: Tools - Options - Debugging - General. Uncheck "Enable property evaluation" option.

This is from Visual Studio 2010. Visual Studio 2008 should have the same option or something similar.

like image 127
Alex F Avatar answered Sep 29 '22 21:09

Alex F


I would imagine that the behaviour you describe is undefined in most documentation. Certainly there's no requirement than any debugger (VS included!) should honour the DebuggerBrowsable attribute. Further, the lack of display of an item in a debug window doesn't necessarily guarantee that the item isn't evaluated by the debugger.

There's an option under the debugging options called "Enable Property Evaluation" that may or may not help your specific case, but in general I'd say you can't rely on this.

There's a commonly-repeated piece of advice: "property getters should not have [visible] side-effects." Your property getters do have side-effects, and that's causing problems with your debugging experience, but it is also possibly making your class as a whole less understandable for other developers. My advice would be to consider a redesign such that getting a property value doesn't alter the content of the list.

like image 43
Dan Puzey Avatar answered Sep 29 '22 21:09

Dan Puzey