To reviewAX 2012

"The enumerator does not designate a valid element" in CIL

In code that runs in CIL, set Map and Set enumerators to null before changing the collection, or a remove throws this error.

Observed in AX 2012 CIL; check Map and Set enumerators in D365FO, where all X++ compiles to CIL.

First written
Re-read
Versions
AX 2012

Code that changed a Map while an enumerator was still alive worked in the client and failed in batch, where AX 2012 ran it in CIL. The difference is the enumerator.

The original note

When your code runs in CIL, remember to set any enumerator of a Set or Map to null before you change the collection. If the enumerator is not reset to null, a remove from a Map throws the error “The enumerator does not designate a valid element.”

References