Search code examples
c#visual-studio-2010debuggingvisual-studio-debugging

Why does Visual Studio fail to set a conditional breakpoint on this simple C# property?


In my C# object, I set a conditional breakpoint with the condition value == "Status" in the setter of this property. Normally it's decorated with a PostSharp aspect, but I've commented that out in this case, and it's still having trouble.

public virtual string Name
{
    get
    {
        return _name;
    }
    set
    {
        _name = value; // breakpoint here
    }
}

The first time execution reaches the breakpoint, VS displays an error:

Visual Studio MessageBox

EDIT - for searchability, the message is this:

The following breakpoint cannot be set:

At (file).cs, line 137 character 17 ('(class).Name', line 12), when 'value == "Status"' is true

The function evaluation requires all threads to run.

Here's what the Threads window looks like:

Debugger Threads window

Anyone seen this before, or have any ideas what might be causing the debugger to baulk at this seemingly-simple case? Might it have something to do with the sleeping thread?


Solution

  • I eventually devised a workaround:

    public virtual string Name
    {
        get
        {
            return _name;
        }
        set
        {
            if (value == "Status")
                DoSomeNoOp(); // Breakpoint here, or Debug.Fail() inside your no-op
    
            _name = value;
        }
    }