Tuesday, December 29, 2015

AX 2012 - AOS Freeze or Crash during CIL Compilation


Hi All

Today I’d like to share an issue that took a lot of my time!
I'm using AX 2012 R3.
At a certain point, the CIL Compilation failed and the AOS crashed or freeze without any errors that could help me.

For my lucky I use TFS so I try to verify the last check-in, one by one.


Finally I found the problem.

The code below cause the AOS Crash or Freeze during CIL Compilation, Incremental and Full as well.


public void updateRecordsetList()

{

    CustInvoiceTable    custInvoiceTable;

    CustinvoiceJour     CustinvoiceJour;

    CustInvoiceLine     CustInvoiceLine;


    update_recordSet CustinvoiceJour

        setting InvoiceAmount = custInvoiceTable.TotalAmount()

        join *

        from custInvoiceTable

        where custInvoiceTable.InvoiceId == CustinvoiceJour.InvoiceId

        join parentRecId, TaxAmount, AmountCur

        from custInvoiceLine

        where CustInvoiceLine.ParentRecId == custInvoiceTable.RecId;

}
 

The “TotalAmount” custom method of the CustInvoiceTable table contain the following query:


Display amount TotalAmount()

{

    CustInvoiceLine     custInvoiceLine;

   

    select sum(AmountCur) from custInvoiceLine

        where custInvoiceLine.ParentRecId == this.RecId;

 

    return custInvoiceLine.AmountCur;

}

I know that the code isn’t properly written, but, I expect an error.

This issue coming after the last Kernel update.

Before, with AX 2012 RTM Kernel, the CIL Compilation raise an error like below.

Error 1. Class: XXXXX, Method: updateRecordsetList, Exception: System.NullReferenceException: Object reference not set to an instance of an object.

   at Microsoft.Dynamics.Ax.Xpp.ILGenerator.processBytecode(XmlNode childNode)

   at Microsoft.Dynamics.Ax.Xpp.ILGenerator.processBytecodes(TypeBuilder typeBuilder, XmlNode node)

   at Microsoft.Dynamics.Ax.Xpp.ILGenerator.GenerateIL(TypeBuilder typeBuilder, XmlNode node)

   at Microsoft.Dynamics.Ax.Xpp.ILGenerator.TraversePCode(XmlNode node)

   at Microsoft.Dynamics.Ax.Xpp.PCodeTraverser.TraverseMethod(XmlNode methodNode)

   at Microsoft.Dynamics.Ax.Xpp.ILGenerator.GenerateXppModule()


So, with the last Kernel Microsoft introduce something…



I raised a Support Case and Microsoft suggestion is been modify the BP check (around line 222) in the “checkSource” method of the “SysBPCheckMemberFunction” class:


        // Check if setting value from valid function in update_recordset statement

        if ((textBuffer.find('update_recordSet'))

         && (textBuffer.find('setting',textBuffer.matchPos()+textBuffer.matchLen()))

         && (textBuffer.find('=',textBuffer.matchPos()+textBuffer.matchLen()))

         && (textBuffer.find('(+)',textBuffer.matchPos()+textBuffer.matchLen()))

           )

        {

            setMatchPosLineAndColumn();

            if (!isComment())

            {

                this.addSuppressableWarning(#BPErrorMethodUpdateRecordSetCheck, matchPosLine, matchPosColumn, strFmt("Are you setting a value from a supported method in update_recordset?"));

            }

        }

With this modification at least the Developer will not be able to compile the object because will raise a BP error.

 
From my point of view, this issue is time consuming because could take a lot of time.

I hope that Microsoft will improve the Compilation process in order to avoid an AOS crash.
I also create a suggestion in Connect, https://connect.microsoft.com/dynamicssuggestions/feedback/details/2182000

Stay Tuned!

No comments: