Search code examples
visual-studio-2008.net-3.5debuggingbreakpointsautomatic-properties

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


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?


Solution

  • 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