Search code examples
vb.netideassert

Debug.Assert() isn't thrown


I have the following code:

enter image description here

As you can see from the quickview tooltip, nNewCell.Style is Nothing. Despite of that, the lines

Debug.Assert(nNewCell.Style IsNot Nothing)
Debug.Assert(nNewCell.Style.GUID <> "")

aren't thrown.

The IDE doesn't raise an exception or stop there, the IDE simply ignores these lines.

My project settings are Debug x86.

What might be causing this problem?


Solution

  • Project Properties ➤ Compile ➤ Advanced Compile Options

    You will see a checkbox for Define DEBUG constant. This must be checked for Debug functions to work. If it's not, they will be ignored and not compiled into your assembly.

    This definitely seems like you are missing the DEBUG constant because your code should be throwing a NullReferenceException due to the line Debug.Assert(nNewCell.Style.GUID <> "") and your screenshot showing it was Nothing.


    One quick note. This issue really simple to cause and I have lost a decent amount of time before tracking down issues related to this. When creating a new configuration, always copy the appropriate type (Debug or Release). Issues like this are usually caused by copying a Release or non-debug config, but then attempting to treat them as Debug.