Monday, April 26, 2010

Switch statement and CLR enums

There is a really weird bug in AX 2009 with CLR enumerations. If the code has "if" statement that validates value of a variable of CLR enum type everything is fine. However, the same "switch" statement fails with kernel exception.
Example:

MyNamespace.MyEnum enum;

enum = MyNamespace.MyEnum::Value1;

if (enum == MyNamespace.MyEnum::Value1)
{
    info("Everything is fine");
}

switch (enum)
{
    case MyNamespace.MyEnum::Value1 :
        info("And not so good here");
        break;
}

Result:
Error executing code: Wrong argument types for comparison.

7 comments:

  1. Well, I can't say that yet:) Will see...

    ReplyDelete