Skip to main content

Notifications

Supply Chain Management forum
Answered

How to find the line of code that is causing the error?

Posted on by 312

Hi friends, my name is Antony.

I recently encountered an error when I posted a Job Card on a Production Order.
The error says:
Unable to cast object of type 'Dynamics.AX.Application.ProdRouteJob' to type 'Dynamics.AX.Application.ProdJournalBOM'.

2262.pastedimage1622908699481v2.png

I've tried to debug this line of code by putting a breakpoint on the class that runs on Post Button and also attaching the process to w3wp.exe.

7343.pastedimage1622909097883v3.png

Then the error appears in output window, but I don't know how to find out which method/class/line is causing the error.
Is this method of debugging is correct? How do I find the line/method that is causing the error?

Any suggestions will be very helpful. Thank you.

  • Michael Antony Profile Picture
    Michael Antony 312 on at
    RE: How to find the line of code that is causing the error?

    Hi Martin. Thanks for your advice.

    I accidentally found the error when I checked the ProdRouteJob extension class. In the event handler method I incorrectly declared a variable that should be ProdRouteJob instead ProdJournalBOM which caused the error.

    But I'll try and learn your suggested approach to dealing with this kind of error.

    Regards,

    Antony

  • Michael Antony Profile Picture
    Michael Antony 312 on at
    RE: How to find the line of code that is causing the error?

    Hi Nikolaos. Thank you for your advice.
    I've tried putting a breakpoint in Classes\Info\add but the call stack doesn't show up when this error occurs.

    Regards,
    Antony

  • Martin Dráb Profile Picture
    Martin Dráb 225,425 Super User on at
    RE: How to find the line of code that is causing the error?

    I don't think that Info.add() is called for managed exceptions like this. At least it didn't work for me the last time when I tried it.

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,146 on at
    RE: How to find the line of code that is causing the error?

    In addition to Martin's suggestion, a general good approach is to put a breakpoint in Classes\Info\add, this way you can always find out the call stack of any process that prints in the infolog. Including your current exception.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 225,425 Super User on at
    RE: How to find the line of code that is causing the error?

    A fast way of finding the place may be configuring Visual Studio to break on InvalidCastException.

    Go to Debug > Windows > Exception Settings, search for InvalidCastException and tick System.InvalidCastException in the list of Common Language Runtime Exceptions. Then attach the debugger and try the process again. The debugger should stop at the place where the exception is thrown.

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 284,874 Super User on at
    RE: How to find the line of code that is causing the error in AX365?

    Hi Michael,

    What is the version of your Dynamics 365 application? Do you have customizations? If so verify if this could be causing it.

    If you don't have customizations, you can search on LCS issue search for known issues. I couldn't find this specific error, but some other which were identical on other application areas. It might be a bug if you don't have customizations yourself. In that case, contact Microsoft Support.

  • Ludwig Reinhard Profile Picture
    Ludwig Reinhard Microsoft Employee on at
    RE: How to find the line of code that is causing the error in AX365?

    moved to the d365 forum

Helpful resources

Quick Links

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Blog subscriptions now enabled!

Follow your favorite blogs

TechTalk: How Dataverse and Microsoft Fabric powers ...

Explore the latest advancements in data export and integration within ...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 284,874 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,425 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,146

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans