It seems the result of key.GetValue is a long when the registry value is a REG_QWORD, and the above code causes an unboxing operation to an int, which fails.
I'm not sure what the "right" way to fix this issue is, but this worked:
object val = key.GetValue("Policy", 0);
if (val is long) {
Policy = (ElevationPolicy)(long)val;
} else {
Policy = (ElevationPolicy)val;
}
This line cause an exception on my machine:
COMIELowRightsElevationPolicy.cs:40 Policy = (ElevationPolicy)key.GetValue("Policy", 0);
It seems the result of key.GetValue is a long when the registry value is a REG_QWORD, and the above code causes an unboxing operation to an int, which fails.
I'm not sure what the "right" way to fix this issue is, but this worked: