Why does the condition for a breakpoint failed to

2020-08-10 07:33发布

问题:

I want to temporarily disable a breakpoint for a short time, so I set a conditional breakpoint with the following condition:

(global::System.DateTime.Now<new global::System.DateTime(2014,03,28,11,0,0))

When this breakpoint is hit a dialog pops up, saying

The condition for a breakpoint failed to execute. The condition was 
'(global::System.DateTime.Now<new
global::System.DateTime(2014,03,28,11,0,0))'. The error returned was
'The runtime has refused to evaluate the expression at this time.'. Click
OK to stop at this breakpoint.

Why has the runtime refused to evaluate the expression?

What can I do to get the desired behavior without modifying the debugged source code?

回答1:

From VS2012 on, you have to switch to the Managed Compatibility Mode, to use conditional breakpoints. Why (sorry, no more why since MS broke that link) and how is described here:

switching-to-managed-compatibility-mode-in-visual-studio-2013

old link, now dead. maybe still in some archives



回答2:

It's not possible as far as I know. What you can do instead is use of HitCount

or hardcode with a timer (as you like) in C# code

#if DEBUG 
  if(System.Diagnostics.Debugger.IsAttached)
     System.Diagnostics.Debugger.Break();
#endif