I found some standard Microsoft code in AX which was working fine in x++ however, when the code executed in IL (Aif Interface), it would throw an error
"Unable to cast object of type 'Dynamics.Ax.Application.DictField' to type 'Dynamics.Ax.Application.SysDictField"
I found that the variable was declared as SysDictField but the object was instantiated as new DictField() - this works fine in x++ but would fail in IL based on OOP principles.
The solution was to change the following line of code from new dictField(...) to new sysDictField(...)
SysDictField dictField;
should be:
dictField = new SysDictField(_variable.RefTableId,_variable.RefFieldId);