Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 344
Tullo_x86 Avatar asked Nov 17 '11 05:11

Tullo_x86


People also ask

How do I set a conditional breakpoint in Visual Studio?

Right-click the breakpoint symbol and select Conditions (or press Alt + F9, C). Or hover over the breakpoint symbol, select the Settings icon, and then select Conditions in the Breakpoint Settings window.

Why breakpoints are 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.

How do I add a conditional breakpoint in Visual Studio code?

In short, right click on an existing breakpoint and select "Edit breakpoint", or right click on the breakpoint margin and select "Add conditional breakpoint".

Why does Visual Studio not stop at breakpoint?

This problem occurs because ASP.NET debugging isn't enabled on the application.


1 Answers

I once had this problem when I encountered a situation when it goes out of the execution of the base thread. A bit more information on the flow of your application will help. It seems to me like a race condition.

like image 105
King Avatar answered Oct 07 '22 00:10

King