Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

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

Posted on by 3,024

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?

Categories:
  • Verified answer
    Mea_ Profile Picture
    Mea_ 60,274 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,024 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,274 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.

Helpful resources

Quick Links

Can you answer this forum question?

You could make someone's day!

Community Newsletter - May 2024

Kudos to our community stars!

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 283,663 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 224,741 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,146

Featured topics

Product updates

Dynamics 365 release plans