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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

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

(0) ShareShare
ReportReport
Posted on by 3,157

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

I have the same question (0)
  • Suggested answer
    Mea_ Profile Picture
    60,286 on at

    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.

  • b_radlyjames Profile Picture
    3,157 on at

    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.

  • Verified answer
    Mea_ Profile Picture
    60,286 on at

    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

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans