Hello all,
This is not really a question, but a cross-post of a bug I reported in Microsoft Connect as Dynamics AX "Feedback". I wanted to put this somewhere that google will pick up, so that others can find it. This bug can take an extremely long time to find (assuming it didn't become apparent when the code was being written). However, this is very easy to fix once you can identify it: just refactor the code so that it doesn't require the offending null assignment.
Here is the bug description:
The AOS will crash when these conditions are met:
- A value of null is assigned to a System.DateTime variable in X++.
- The X++ code is being executed in a Batch Job (ex: in the run() method a class extending RunBaseBatch).
The crash will occur as soon as execution attempts to enter the method containing the null assignment. In other words, the crash happens as soon as the method is called, before *any* statements inside the method are executed.
If this is executed unconditionally within a batch job, then the AOS will become unable to restart successfully. This happens because the batch job remains in the batch queue, and is restarted along with the AOS, where it proceeds to execute the code that crashed the AOS. This can be difficult to resolve; one possibility is to access the AOS's SQL database directly and run an update statement that will set the batch job to withhold status, like this one:
UPDATE BATCHJOB SET STATUS = 0 WHERE BATCHJOB.[STATUS] = 2 AND BATCHJOB.CAPTION = 'AOS Crasher';
After that, the AOS can be restarted successfully, thus allowing the cause to be removed.
The event log will show a warning that states "Attempt to clear pointerMap when it still contains objects", followed by an error like this:
Faulting application name: Ax32.exe, version: 6.3.3000.111, time stamp: 0x564fc172
Faulting module name: KERNELBASE.dll, version: 6.3.9600.18340, time stamp: 0x5736541b
Exception code: 0xc0020001
Fault offset: 0x00014878
Faulting process id: 0x3e39c
Faulting application start time: 0x01d22aedb0d5d9d3
Faulting application path: C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin\Ax32.exe
Faulting module path: C:\Windows\SYSTEM32\KERNELBASE.dll
Report Id: 41a38b2b-96ee-11e6-80d9-0050568e5425
Faulting package full name:
Faulting package-relative application ID:
Reproduction step 1:
Create a job and class with contents as follows:
// Job
static void CrashAOS(Args _args)
{
BatchHeader batchHeader;
CDJ_AOSCrasher crasher;
batchHeader = BatchHeader::construct();
batchHeader.parmCaption("AOS Crasher");
crasher = new CDJ_AOSCrasher();
batchHeader.addTask(crasher);
batchHeader.save();
}
class CDJ_AOSCrasher extends RunBaseBatch
{
}
// Member of CDJ_AOSCrasher
public void run()
{
System.DateTime currentDateTime;
//System.Object currentDateTime; // No crash.
// This statement is expected to have no effect, and allow the run() method
// to return immediately.
// Instead, it will cause the AOS to crash any time the batch starts.
currentDateTime = null;
}
Reproduction step 2:
Run the job.
Within 1 minute the AOS should crash.
As mentioned in the bug description, restoring the AOS completely may require unusual activities such as modifying AX records (batch job entries) directly from SQL.