IDynamicsAXExpressionBuilder returned error code 0x80131509

In forms that are using the ActiveX-control ExpressionBuilder (like TrvPolicyForm) you might be faced to the following error message:

Method 'initialize' in COM object of class 'IDynamicsAXExpressionBuilder' returned error code 0x80131509 (<unknown>) which means: End enum not found.

This is caused by an enumerator that is used by the ActiveX-control. The method "initialize" of that ActiveX-control requires in its first parameter the expression in a Xml-document. That Xml-document contains also a list of enumerators.

Find the method, get the content of this Xml-document with the debugger and then list the enumerators that this Xml-document contains. Verify that there is no empty Enum like  for example <enum name="HRMSalutation" /> . If you do find such an empty Xml-element, verify the order of the enum-elements in the AOT. Change the order of the elements in the AOT, so that the elements are in the order of its values.

(Update 07/08/2009):

Since I was asked where to find the initailize calls, here the lines:

WorkflowConfigConditionControl.setData:
 conditionControl.initialize(data.parmConditionDesignTimeProjection(), expressionTable.ExpressionDefinition);

WorkflowConfigConditionControl.clicked:
 conditionControl.initialize(data.parmConditionDesignTimeProjection(), expressionTable.ExpressionDefinition);

If this happens in the TrvPolicyForm, just search for 'initialize'.

Just get the Xml-expression for data.parmConditionDesignTimeProjection() and copy and pate the xmlString into any Xml editor (Visual Studio or Xml-Spy). You will find the enumerations used by this expression at the end of the Xml document in the Xml-Element 'enumerations'.

(Update 18/08/2009):

This problems seems to be related to a verification for the last element. So at the end this problem occurs if the last element is not the expected one... Well at least it is now clear how to evoid this strange bahavior.

  (Update 20/08/2009):

The origine of this issue can be found in the method 'buildEnumerationXml' of the class 'SysExpression':

Currently, a loop iterates until the last element:

for (i = sysDictEnum.firstValue(); i <= sysDictEnum.lastValue(); i = sysDictEnum.nextValue(i))

I you replace this (sysDictEnum.lastValue(); ) by the number of elements (sysDictEnum.values();) the issue is solved.