Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Unable to cast object of type 'Dynamics.Ax.Application.LedgerJournalEngine' to type 'Dynamics.Ax.Application.LedgerJournalEngine_VendInvoice'.

Posted on by 3,061

I came across an issue recently where my Timesheets wouldn't post in 'Batch'.

It turns out that it wouldn't perform the following code in 'Batch', but would be fine doing it in the Client.

LedgerJournalEngine_VendInvoice         ledgerJournalEngine;

ledgerJournalEngine = LedgerJournalEngine::construct(LedgerJournalType::VendInvoiceRegister);

If we go to the 'construct' method, we will see it returns the 'default' in the switch case:

default :

            ledgerJournalEngine = new LedgerJournalEngine(_formRun);

When running this in the client, it works fine.  When running it in 'Batch' on the server, it fails:

Unable to cast object of type 'Dynamics.Ax.Application.LedgerJournalEngine' to type 'Dynamics.Ax.Application.LedgerJournalEngine_VendInvoice'.

This does make sense that you can't cast a 'Child' class to it's 'Parent', however, why would this work on the Client but not in Batch?

*This post is locked for comments

  • Verified answer
    Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: Unable to cast object of type 'Dynamics.Ax.Application.LedgerJournalEngine' to type 'Dynamics.Ax.Application.LedgerJournalEngine_VendInvoice'.

    Because client use x++ that is a bit relaxed on types. Batch is executed in CIL and .Net framework does not allow you to do this. Here is a nice blog describing what is not possible in .Net and is possible in x++, so it will work on client but will fail in Batch or CIL session blogs.msdn.microsoft.com/.../changes-to-the-collection-classes-in-dynamics-ax-2012

  • b_radlyjames Profile Picture
    b_radlyjames 3,061 on at
    RE: Unable to cast object of type 'Dynamics.Ax.Application.LedgerJournalEngine' to type 'Dynamics.Ax.Application.LedgerJournalEngine_VendInvoice'.

    Yes, this is a mod.  Yes, I already changed it to 'LedgerJournalEngine'.

    I still can't understand why it works in the client but not batch... Just doesn't make sense.

  • Suggested answer
    Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: Unable to cast object of type 'Dynamics.Ax.Application.LedgerJournalEngine' to type 'Dynamics.Ax.Application.LedgerJournalEngine_VendInvoice'.

    Hi bRradlyJames,

    Is this a mod because I cannot find anything similar in standard code ? Anyway it should be:

    LedgerJournalEngine ledgerJournalEngine;

    ledgerJournalEngine = LedgerJournalEngine::construct(LedgerJournalType::VendInvoiceRegister);

    So if it is a mod just change it to code above, if it is standard stuff there should be hotfix for it in LCS.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans