Home > Ax Technical > Debug::assert statements found in Sys layer in Dynamics Ax 2009

Debug::assert statements found in Sys layer in Dynamics Ax 2009

This morning I was surprised to see Debug::assert statements in Sys layer table object as I was traversing the InventTrans tree node.

[Sorry for wrongly pressing the panic button… 😉 This seems to be pretty common with new versions of Ax. Please see comments from Kashperuk]

If you look at \Data Dictionary\Tables\InventTrans\Methods\unpostedInvoiceIdForReceivedPurchType method then you will find more then 5 assert statements in it. I quickly checked where this method is being used from. It was called from a display method inside the same table. Luckily one of our developer have commented it during rollup upgrade. This statement can attempt to open the debugger if the assertion is false. So I guess it would be good if you would do something to prevent it.

Hope anybody from Microsoft following this blog would take it further to fix it…..

Advertisement
  1. lillabjörnen
    March 8, 2011 at 9:42 am

    Maybe it is common in AX 2009. But anyway it is no good idea to do it.
    Debug.assert() will invoke the call stack and pause further execution of code if there is a debugger.
    The problem is the words PAUSE and IF THERE IS A DEBUGGER
    In production environment you don’t have a debugger and therefore debug.assert() will do nothing and code execution is going on.
    So if there is something VERY wrong, you are now in problems. Your process in production will maybe fail somewhere later in the code with a runtime eror. And you don’t know why, cause you missed the nice condition tested in debug assert.

    There is a nice article about it: http://www.sharplogic.com/blogs/ed/PermaLink,guid,976a0613-da9b-433e-b909-07d37ce407b2.aspx

  2. July 19, 2010 at 8:56 am

    ———- Comments From Kashperuk in axforum.info —————————–
    Actually, you’ll see a lot more of those in the new AX release.
    There is nothing wrong with putting such statements into the code.

    Their purpose is to assert a very specific condition, that MUST be satisfied.
    If it is not, something is VERY wrong, and we should not continue.
    They are intended for developers changing the code – when doing some testing of the changes, you would be able to easily see that something is wrong.

    So, again – this is a good thing that they are there.
    ———————————————————–

  1. January 30, 2012 at 12:43 am
  2. July 25, 2010 at 1:20 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: