Can't set breakpoints on an auto-property setter ? Why?
Asked Answered
Z

4

28

Apparently VS 2008 does not allow setting a breakpoint just on the setter of an auto-property.

I.e. if I define an auto-property like this:

    public int CurrentFramesize
    {
        get; 
        protected set;
    }

and then try to set a breakpoint on the setter line, the whole auto-property turns breakpoint-red.

This works just fine for normal properties, so any idea why auto-properties get this special (restrictive) treatment? Are they more than just syntactic sugar to normal properties with a hidden backing field?

Zodiac answered 21/4, 2010 at 11:57 Comment(6)
You are correct. I noticed the same thing.Dorelle
Microsoft's response connect.microsoft.com/VisualStudio/feedback/details/408762/…Chrischrism
I was desparately hoping ths feature would make it into VS2010 :(Prospective
@Prospective ... and I assume it didn't? :(Zodiac
You are assuming correctly. It still doesn't work in VS 2010.Prospective
possible duplicate of Debugging automatic propertiesCole
B
33

Using Visual Studio 2008, 2010, 2012:

  1. Go to the Breakpoint window
  2. New->Break at Function…
  3. For the get, type: ClassName.get_CurrentFramesize()

    For the set, type: ClassName.set_CurrentFramesize(int)

You'll get a "No Source Available" when the breakpoint is hit, but you'll get the calling location in the call stack.

I found this solution here: http://social.msdn.microsoft.com/Forums/en/vsdebug/thread/b1dd0dc3-e9c1-402a-9c79-a5abf7f7286a

See also: Debugging automatic properties

Belleslettres answered 15/7, 2011 at 22:41 Comment(2)
Somehow I missed your answer for two and a half years. +1 and accepted! :)Zodiac
Works in Visual Studio 2019, (the point 2. being New-> Function Breakpoint...Stanleigh
Z
2

The short answer is: this bug feature ended up on the cutting room floor for VS2008.

(Longer answer - hat tip @jdk)

All we've got is a vague promise that it's being considered for vNext.

Zodiac answered 29/4, 2010 at 21:55 Comment(0)
S
-3

No you can't set a break point on them, but then what would you check? The variable for storage of the auto-property is only assigned at runtime and as such there isn't a variable for the debugger to show/access.

Saleswoman answered 21/4, 2010 at 12:4 Comment(2)
You might want to check when it's assigned, if it seems to get a wrong value from "somewhere".Allegra
@Hans Kesting: Spot on. The CLR debugger doesn't have data breakpoints, so if this would be supported, it would be the next best thing.Zodiac

© 2022 - 2024 — McMap. All rights reserved.