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 :
Microsoft Dynamics AX (Archived)

AIFFault object does not have method 'new'

(0) ShareShare
ReportReport
Posted on by 150

Hi All,

I have created a custom service to do the post Prod Journal logic.

When I test it in the AX , everything can go well, the journal can be posted success.

But when I try to call the interface from my .net program, it show me the error "AIFFault object does not have method 'new'".(This issue happen in today, in the before, the interface can run well)

I have traced and find the issue is happen in the code of posting journal below.

ProdJournalCheckPostProd::newPostJournal(prodJournalProd.JournalId, false).run();

I have checked the ProdJournalCheckPostProd class, nothing is missing, every method are there.

In order to fix the issue of "AIFFault object does not have method 'new'", I have generated full CIL, but it does not work. (When I do the generate full CIL, there still have multiple user connect to the server, is that I should log them off then do the generate full CIL again?)

I don't what should I do except generate full CIL, anybody can give me a suggestion?

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,967 Most Valuable Professional on at

    If you can't generate CIL, this may indeed be the problem. I wouldn't spend more with investigation before getting latest code in place.

  • Nick Bi Profile Picture
    150 on at

    Hi Martin,

    Thanks for your focus. Currently, my situation is that I can generate CIL, but after generating CIL, the issue still there. This issue just happen when I call it from .net.

    Below is the method. I have added throw error code to confirm the issue is happening in the post logic.

    As my understanding, maybe there still something missing after generating CIL, but how to check it? 

    ----------------------

    [SysEntryPointAttribute]
    public str SubmitProdJournal(ProdId _prodId, DataAreaId _dataAreaId,ProdQtySched _QtyFinishedGood )
    {
    str ret;

    ProdJournalTable prodJournalTable;
    ProdJournalProd prodJournalProd;
    ProdTable prodTable;
    ProdBOM prodBom;
    InventTable inventTable;


    if (_dataAreaId == "")
    {
    _dataAreaId = "2101";
    }


    changeCompany(_dataAreaId)
    {
    try
    {
    ttsBegin;
    prodTable = null;
    select prodTable
    where prodTable.ProdId == _prodId && prodTable.dataAreaId == _dataAreaId;

    prodJournalTable.clear();
    prodJournalTable.initValue();
    prodJournalTable.JournalType = ProdJournalType::ReportFinished;
    prodJournalTable.JournalNameId = 'PrdFinish';
    prodJournalTable.Description = "";
    prodJournalTable.ProdId = prodTable.ProdId;
    prodJournalTable.VoucherDraw = JournalVoucherDraw::Post;
    prodJournalTable.VoucherSeqRecId = NumberSequenceTable::find(ProdParameters::numRefProdJournalVoucherId().NumberSequenceId).RecId;
    prodJournalTable.insert();

    prodJournalProd.JournalId = prodJournalTable.JournalId;
    prodJournalProd.ProdId = prodTable.ProdId;
    prodJournalProd.QtyGood = _QtyFinishedGood;
    prodJournalProd.QtyError = 0;
    prodJournalProd.ErrorCause = ProdErrorCause::Machine;
    prodJournalProd.TransDate = today();

    prodJournalProd.InventTransId = prodTable.InventTransId;
    prodJournalProd.ItemId = prodTable.ItemId;
    prodJournalProd.InventDimId = prodTable.InventDimId;
    prodJournalProd.PmfProductType = inventTable.PmfProductType;
    prodJournalProd.insert();

    prodJournalTable.selectForUpdate(true);
    prodJournalTable.NumOfLines = 1;
    prodJournalTable.update();

    //throw error("Test Error 1");

    ProdJournalCheckPostProd::newPostJournal(prodJournalProd.JournalId, true).run();

    //throw error("Test Error 2");

    //ttsCommit;
    ttsAbort;
    }catch
    {
    ttsAbort;
    return 'False,'+infolog.text();
    }
    ret = 'Ture';

    }
    return ret;
    }

  • Martin Dráb Profile Picture
    237,967 Most Valuable Professional on at

    Which line of code is throwing the exception? I thought you said it's ProdJournalCheckPostProd.run(), not in SubmitProdJournal().

    Also, your error handling looks very strange to me. The usually approach in modern programing is not returning a status value, but throwing an exception if something fails. Why don't you do that?

    Not only your approach is non-standard, it's also not going to work, because the service is already wrapped in a transaction and therefore your catch clause will be ignored.

    In fact, what you're trying to achieve is already covered by standard logic. Call your service and if it completes, it's an equivalent of your code returning 'Ture'. If there is an exception, a FaultException object is created which you can catch in your .NET code and read the message from there.

    By the way, if you want to return multiple values, use a data contract class. Combining multiple values to a string (and parsing it later), like you do with the status and the message, doesn't make a good sense to me. When you use correct types (such as boolean for true and false), you'll also avoid typos like 'Ture'.

  • Nick Bi Profile Picture
    150 on at

    Hi Martin,

    Sorry for my confusing description. Yes, it is the ProdJournalCheckPostProd.run() throwing the exception.

    When I debug the CIL code from visual studio, I can get the result of posting journal in the method below(ournalCheckPost.infologPack method), but the system throw the exception "AifFault object does not have method 'new'" when run the red highlighted code.

    Translation of the result of posting journal:"\t\t Posting - production journal \t journal: prd-b0000090 \t line no. : 1.00\t production no: wo-000000005 \t only users in user group finance closing can post in module production during the period containing date 2019/3/3".

    6153.pic1.png

    I am thinking that the system should return the result info of posting journal, not the exception "AifFault object does not have the method 'new'“.

  • Nick Bi Profile Picture
    150 on at

    For the error handling, it is because I want to get the whole result info of posting journal like the info below.

    "\t\t Posting - production journal \t journal: prd-b0000090 \t line no. : 1.00\t production no: wo-000000005 \t only users in user group finance closing can post in module production during the period containing date 2019/3/3".

    If I throw the an exception directly, I just can get a simple AifFault info "Update is canceled".

    This is the reason why I use the try.. catch.

  • Nick Bi Profile Picture
    150 on at

    Currently, I have no any idea about the reason of this issue.

  • Verified answer
    Martin Dráb Profile Picture
    237,967 Most Valuable Professional on at

    Great, now we're making progress.

    If AifFault class in AX 2012 is the same as in D365FO, this code is expected to fail. The reason is that the constructor of AifClass requires parameters, which aren't provided by code above. But D365FO uses different code to create the SysInfoAction objects, which handles AifFault correctly.

    Try if installing KB 4342199 doesn't fix that.

    If not, you can backport the solution from D365FO to AX 2012. It's very simple:

    if (classId == classNum(AifFault))
    {
        sysInfoAction = new AifFault(1, "", "");
    }
    else
    {
        DictClass dictClass = new DictClass(classId);
        sysInfoAction = dictClass.makeObject();
    }
  • Martin Dráb Profile Picture
    237,967 Most Valuable Professional on at

    As I said, your catch clause wouldn't work. To get infolog message, try enabling "Include exceptions if fault" on your inbound port and then examining the Details property of the FaultException object you catch in your client application.

  • Nick Bi Profile Picture
    150 on at

    Hi Martin,

    Thanks for your guidance!!! Since I don't work on the AX very often, I even don't know the "Include exceptions if fault" option in the inbound before, now I learn it.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans