{"record":{"id":"905a3db242768b36","repo":"Unity-Technologies/UnityCsReference","slug":"parameter-enumvalue-must-be-of-type-system-enum","errorCode":null,"errorMessage":"Parameter enumValue must be of type System.Enum","messagePattern":"Parameter enumValue must be of type System\\.Enum","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/EditorGUI.EnumMaskField.deprecated.cs","lineNumber":91,"sourceCode":"        public static Enum EnumMaskPopup(Rect position, GUIContent label, Enum selected, GUIStyle style)\n        {\n            int changedFlags;\n            bool changedToValue;\n            return EnumMaskPopup(position, label, selected, out changedFlags, out changedToValue, style);\n        }\n\n        [Obsolete(\"EnumMaskField has been deprecated. Use EnumFlagsField instead.\")]\n        static Enum EnumMaskField(Rect position, GUIContent label, Enum enumValue, GUIStyle style, out int changedFlags, out bool changedToValue)\n        {\n            return DoEnumMaskField(position, label, enumValue, style, out changedFlags, out changedToValue);\n        }\n\n        [Obsolete(\"EnumMaskField has been deprecated. Use EnumFlagsField instead.\")]\n        static Enum EnumMaskFieldInternal(Rect position, Enum enumValue, GUIStyle style)\n        {\n            Type enumType = enumValue.GetType();\n            if (!enumType.IsEnum)\n                throw new ArgumentException(\"Parameter enumValue must be of type System.Enum\", \"enumValue\");\n\n            var names = Array.ConvertAll(Enum.GetNames(enumType), ObjectNames.NicifyVariableName);\n            int flags = MaskFieldGUIDeprecated.DoMaskField(\n                IndentedRect(position),\n                GUIUtility.GetControlID(s_MaskField, FocusType.Keyboard, position),\n                Convert.ToInt32(enumValue),\n                names, style);\n            return EnumDataUtility.IntToEnumFlags(enumType, flags);\n        }\n\n        [Obsolete(\"EnumMaskField has been deprecated. Use EnumFlagsField instead.\")]\n        static Enum EnumMaskFieldInternal(Rect position, GUIContent label, Enum enumValue, GUIStyle style)\n        {\n            Type enumType = enumValue.GetType();\n            if (!enumType.IsEnum)\n                throw new ArgumentException(\"Parameter enumValue must be of type System.Enum\", \"enumValue\");\n\n            var id = GUIUtility.GetControlID(s_MaskField, FocusType.Keyboard, position);","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/EditorGUI.EnumMaskField.deprecated.cs#L73-L109","documentation":"Thrown by the deprecated EnumMaskFieldInternal (no-label overload) when enumValue.GetType().IsEnum is false. Because the parameter is typed 'Enum', passing null throws NullReferenceException at .GetType() before reaching this check; the ArgumentException is reached only when a non-enum value is boxed as System.Enum via an invalid cast. The whole method is [Obsolete] — use EnumFlagsField.","triggerScenarios":"Calling EditorGUI.EnumMaskField (deprecated) with a value that is not actually an enum, e.g. an int or a class boxed and cast to Enum via unsafe means. Reachable through reflection-driven generic code that lost the enum constraint.","commonSituations":"Legacy code predating EnumFlagsField; reflection helpers that build mask fields generically and pass a boxed non-enum; ported UI code.","solutions":["Migrate to EditorGUI.EnumFlagsField / EnumFlagsFieldPopup, which carry a proper generic/Enum constraint.","Type-check before calling: if (value == null || !value.GetType().IsEnum) reject.","Ensure the source of the value is statically typed as a concrete enum, not object."],"exampleFix":"// before\nEnum v = (Enum)(object)someInt;\nEditorGUI.EnumMaskField(rect, v);\n// after\n[Flags] enum MyFlags { A = 1, B = 2 }\nMyFlags v = MyFlags.A | MyFlags.B;\nEditorGUI.EnumFlagsField(rect, v);","handlingStrategy":"type-guard","validationCode":"if (enumValue == null || !enumValue.GetType().IsEnum)\n    throw new ArgumentException(\"enumValue must be an enum\", nameof(enumValue));","typeGuard":"static bool IsEnumValue(Enum v) => v != null && v.GetType().IsEnum;","tryCatchPattern":null,"preventionTips":["Migrate off the deprecated EnumMaskField to EnumFlagsField.","Keep values statically typed as concrete enums at call sites.","Type-check before invoking via reflection."],"tags":["editor","imgui","deprecated","enum","type-mismatch","mask-field"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}