18

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?

3

2 Answers 2

23

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

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

old Microsoft link, now dead

the original Microsoft article on archive.org

4
  • 4
    It's odd that they don't even mention conditional breakpoints as one of the reasons to switch to the older mode!
    – Sandra
    Commented Dec 16, 2015 at 16:25
  • 2
    Yes, it works after switching to the compatibility mode.
    – Sandra
    Commented Jan 12, 2016 at 14:12
  • 1
    Dead link, this seems to work. Commented Jun 3, 2020 at 13:12
  • I added the broken article back from archive.org Commented Dec 4, 2020 at 16:25
-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
4
  • hard coding is not an option as you cannot change the behavior during a debug session, hit count would require statistical data upfront to have any timely meaning
    – mbx
    Commented Mar 28, 2014 at 9:52
  • @mbx: what behaviour are you talking about ?
    – Tigran
    Commented Mar 28, 2014 at 9:55
  • behaviour for a breakpoint - can change the condition at runtime during a debug session - just break, change the condition for the breakpoint and continue
    – mbx
    Commented Mar 28, 2014 at 9:57
  • @mbx: HitCount is best what you can basically afaik, for this case.
    – Tigran
    Commented Mar 28, 2014 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.