How to make Debug.Assert work?

I remember it works long before, but it never works now.

I have defined DEBUG symbol, build in Debug configuration, turn on "break when any Exception throw" option, but the Debug.Assert never assert even the condition is false.

I am using Whidbey Beta2. Is there anything wrong in my settings

Thanks!





Answer this question

How to make Debug.Assert work?

  • Juan T. Llibre

    Hi Lei,

    It cant be the IDE settings since it worked for the other project. So it has to be the project settings. Compare the .csproj/.vbproj file that u have with the other file to see if u can locate any specific setting that has been changed in the project file.

    Regards,
    Vikram

  • Anjan Ghose

    Hi,

    Just to check if the build went OK, add the following statement in the Form_load or someplace where it would get executed and see if the MessageBox comes up. This way you will know if the DEBUG constant is available at runtime or not.

    Did you copy the EXE from the machine where it worked and try

    #if
    DEBUG

    MessageBox.Show("DEBUG Defined");

    #endif

    Regards,
    Vikram



  • levyuk1

    I have compared the project settings but there is no difference. If it's caused by project settings, why it works under the same project settings on another machine

    Thanks!


  • Josue Perez

    i see the same behaviour here. only happens in our large project, doesn't repro in normal apps. i opened a case in ladybug. ( http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx feedbackid=df98cdcd-ee58-4ac9-accb-a16de2e2a369 )

    WM_FYI
    thomas woelfer
    http://www.die.de/blog


  • David Spectorman

    I just create a simple WinForm app in VS.NET 2005 Beta2 and add Debug.Assert(false) in the first line of Main method. However, this time it works!

    It just does not work in my large project I mentioned before. I doubt I have changed some settings of the project or VS.NET IDE and caused this problem.

  • BradA-MSFT

    Hi,

    Are you using C# or Visual Basic I tried using C# and it works. Sample I used is below:

    Debug.Assert("st" != "st");

    You need to check the "Define DEBUG constant and Define TRACE constant in the Build Properties in VS2005.

    Regards,
    Vikram



  • Prash_outlawerz

    I think I got the same problem:

    - Debug.Assert() does not work in a specific c# class library;
    - It works correctly in other class libraries and console applications;
    - DEBUG is defined and build/run are done in DEBUG mode;
    - The Assert message is printed out in the output, for failed asserts in this class library;

    - The Assert is ignored and execution continues normally, for failed asserts in this class library;
    - No Asser dialog is presented;
    - Consistent behaviour - always happens for this class library;

    With the help of the link of the previous post, I found that i could not do: new UIPermission(UIPermissionWindow.SafeSubWindows).Demand()

    This happened because my assembly had security permissions that would not allow it, so I commented out the following lines, in the AssemblyInfo.cs file:

    //[assembly: SecurityPermission(SecurityAction.RequestMinimum, Execution = true)]
    //[assembly: PermissionSet(SecurityAction.RequestOptional, Name = "Nothing")]

    Hope this helps anyone!


  • Doublezeta

    Of course I have done this.

    The same program does not throw assert exception either on the machine of one of my colleague, but works fine for another colleague! So there must be some configuration difference between these machines. However, we have checked all settings and they are all the same. Maybe we omitted something

    Thanks!

  • Andy Leonard

    Hi,

    Do a simple test. Build the .Exe on the machine where it is working and then run on ur machine and see if it works Do the other way round, by building on ur machine then running ur colleague's machine.

    Then we can know if its a compile time issue or a runtime issue and do further investigation based on that.

    Regards,
    Vikram

  • How to make Debug.Assert work?