We recently came across an issue when we are interrogating the model metadata through a batch process (which uses CIL), in Microsoft Dynamics AX 2012/ 2012 Feature Pack. We get the following error:
The expected type was str, but the encountered type was enum.
The issue is isolated to the class SysModelMetaData. The new() method of this class instantiates two of its Map objects using the wrong data types for the map key value.
xRefKind2Concept = new Map(Types::String, Types::Class);
utilElementType2Concept = new Map(Types::String, Types::Class);
Changing the code as highlighted below, helps to workaround this error:
private void new()
{
concepts = new List(Types::Class);
groupingNodes = new List(Types::Class);
path2Image = new Map(Types::String, Types::Integer);
path2GroupNodeType = new Map(Types::String, Types::Enum);
xpoToken2Concept = new Map(Types::String, Types::Class);
/*
xRefKind2Concept = new Map(Types::String, Types::Class);
utilElementType2Concept = new Map(Types::String, Types::Class);
*/
xRefKind2Concept = new Map(Types::Enum, Types::Class);
utilElementType2Concept = new Map(Types::Enum, Types::Class);
//If the init mehtod isn’t compiled ok, it will prevent the AOS from starting if invoked
if (new SysDictMethod(UtilElementType::ClassInstanceMethod, classNum(SysModelMetaData), methodStr(SysModelMetaData, init)).compiledOk())
{
this.init();
}
else
{
throw error(strFmt(“@SYS86011”, strFmt(“%1.%2()”, classStr(SysModelMetaData), methodStr(SysModelMetaData, init))));
}
super();
}
–author: | Mansour Yahya Mohamad |