Causing VS2010 debugger to break when Debug.Assert fails

后端 未结 7 2106
南笙
南笙 2020-12-15 09:15

Is there any way to cause Visual Studio 2010 to break while debugging when the argument of Debug.Assert evaluates to false?

Example: in my

7条回答
  •  失恋的感觉
    2020-12-15 09:42

    It seems to work as expected for me in a console application at least: in debug builds, a dialog pops up that allows you to break into the application using the debugger, but in release builds, nothing happens. Admittedly, I just used a simplistic Debug.Assert(false);, but I don't see why that should make much of a difference. I'm running Visual Studio 2010 SP1 Ultimate.

    I'd suggest that you take a close look at your build settings.

    Here's the code I used:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data;
    
    namespace ConsoleApplication
    {
        class Program
        {
            static void Main(string[] args)
            {
                System.Diagnostics.Debug.Assert(false);
    
                Console.ReadLine();
            }
        }
    }
    

提交回复
热议问题