Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 388
Cristian Diaconescu Avatar asked Apr 21 '10 11:04

Cristian Diaconescu


People also ask

Why are my breakpoints not working?

If a source file has changed and the source no longer matches the code you're debugging, the debugger won't set breakpoints in the code by default. Normally, this problem happens when a source file is changed, but the source code wasn't rebuilt. To fix this issue, rebuild the project.

What allows to set breakpoints?

Set breakpoints in source code To set a breakpoint in source code, click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.

How do I enable breakpoints in Vscode?

Breakpoints can be toggled by clicking on the editor margin or using F9 on the current line. Finer breakpoint control (enable/disable/reapply) can be done in the Run and Debug view's BREAKPOINTS section.


1 Answers

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

like image 99
Matt Smith Avatar answered Sep 28 '22 01:09

Matt Smith