web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Can you stop debugger hitting Debug::assert?

(0) ShareShare
ReportReport
Posted on by 4,075

I have some code that I am trying to debug, but the debugger keeps stopping in Debug::Assert.

/// 
    /// Asserts the value of the passed in expression.
    /// 
    /// Expression to assert
    [Hookable(false)]
    public static void assert(boolean  _expression)
    {
        if (!_expression)
        {
            const int numberOfStackFramesToSkip = 2;
            var trace = new System.Diagnostics.StackTrace(numberOfStackFramesToSkip); // avoid the assert() method frame (and 'assert() one)
            XppRuntimeEventSource::EventWriteDebugAssert(trace.ToString());

            if (Debug::debuggerIsAttached())
            {
                System.Diagnostics.Debugger::Break();
            }
        }
    }

It seems its calling the Debug::Assert statement in some of the standard code in DimensionStorage that calls it, and I can't get passed it.
Every time I press Continue, it simply stops at it again.

Can I stop it from hitting it in some way?

I have the same question (0)
  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Rudi,

    Which method are you debugging in DimensionStorage?

    If the debugger is stopping at this statement, can you not set the parameter "_expression" to true in the watch window so that you can continue debugging?

  • Rudi Hansen Profile Picture
    4,075 on at

    I am not debugging DimensionStorage, I am debugging my own code.

    If I change the _expression to true, it just continues and hits the Debug::assert code again, and _expression is then false again.

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Rudi,

    I don't see anyway we can disable the code. I think the only way you can disable the code is by making sure the condition is true.

    Could you please share your code as well? We can check if we can control the value in some way so that the assertion is always true.

  • Rudi Hansen Profile Picture
    4,075 on at

        [FormDataFieldEventHandler(formDataFieldStr(LedgerJournalTransDaily, LedgerJournalTrans, LedgerDimension), FormDataFieldEventType::Modified)]
        public static void LedgerDimension_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
        {
            LedgerJournalTrans  ledgerJournalTrans = sender.dataSource().cursor();
    
            ledgerJournalTrans.TaxItemGroup = TaxItemGroupRuleSearch::getTaxItemGroup(ledgerJournalTrans.LedgerDimension,ledgerJournalTrans.TransDate);
        }

    Sure I am just adding an event handler to the LedgerDimenson field on LedgerTransDaily.

    But it hits the Debug::Assert code way before it hits my code.

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Rudi,

    Maybe some setup is missing in that case. Which method in DimensionStorage is being called (which is causing the issue)?

  • Rudi Hansen Profile Picture
    4,075 on at

    D365Stackpg.jpg

    It seems to be hitting DimensionStorage::find

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    I thought as much. There are 9 Debug::assert() calls here related to the ledger dimension passed and the hierarchy structure.

    You could probably skip these calls as well by placing a breakpoint here (highlighted in red) and setting the next statement to the highlighted (in yellow) line.

    pastedimage1601327764988v1.png

  • Rudi Hansen Profile Picture
    4,075 on at

    Well it kind of works, but still it calls this method so meany times, so far I have skipped it 10 times, and it keeps coming back.

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Rudi,

    The only other option would be to setup the account structures properly and make sure that the assert conditions are always true.

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi Rudi,

    Unfortunately, it's how debugger::break method works and you can't prevent hitting it with the attached debugger. Since Debug::assert is not hookable you can't modify it via CoC to pass always true value in "expression" parameter.  Maybe you can consider other ways of debugging like using infolog, if assert method is too annoying.

    docs.microsoft.com/.../system.diagnostics.debugger.break

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 584 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 499 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 254 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans