{"record":{"id":"adef04b89f202343","repo":"dotnet/wpf","slug":"value-frameworkcontentelement","errorCode":null,"errorMessage":"value","messagePattern":"value","errorType":"exception","errorClass":"InvalidEnumArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkContentElement.cs","lineNumber":1490,"sourceCode":"            }\n\n            set\n            {\n                Debug.Assert((uint)InternalFlags.InheritanceBehavior0 == 0x08);\n                Debug.Assert((uint)InternalFlags.InheritanceBehavior1 == 0x10);\n                Debug.Assert((uint)InternalFlags.InheritanceBehavior2 == 0x20);\n\n                const uint inheritanceBehaviorMask =\n                    (uint)InternalFlags.InheritanceBehavior0 +\n                    (uint)InternalFlags.InheritanceBehavior1 +\n                    (uint)InternalFlags.InheritanceBehavior2;\n\n                if (!this.IsInitialized)\n                {\n                    if ((uint)value < 0 ||\n                        (uint)value > (uint)InheritanceBehavior.SkipAllNext)\n                    {\n                        throw new InvalidEnumArgumentException(\"value\", (int)value, typeof(InheritanceBehavior));\n                    }\n\n                    uint inheritanceBehavior = (uint)value << 3;\n\n                    _flags = (InternalFlags)((inheritanceBehavior & inheritanceBehaviorMask) | (((uint)_flags) & ~inheritanceBehaviorMask));\n\n                    if (_parent != null)\n                    {\n                        // This means that we are in the process of xaml parsing:\n                        // an instance of FCE has been created and added to a parent,\n                        // but no children yet added to it (otherwise it would be initialized already\n                        // and we would not be allowed to change InheritanceBehavior).\n                        // So we need to re-calculate properties accounting for the new\n                        // inheritance behavior.\n                        // This must have no performance effect as the subtree of this\n                        // element is empty (no children yet added).\n                        TreeWalkHelper.InvalidateOnTreeChange(/*fe:*/null, /*fce:*/this, _parent, true);\n                    }","sourceCodeStart":1472,"sourceCodeEnd":1508,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkContentElement.cs#L1472-L1508","documentation":"Setting FrameworkContentElement.InheritanceBehavior with a value outside the defined InheritanceBehavior enum range throws InvalidEnumArgumentException naming the 'value' parameter. The setter validates the raw integer before storing it in internal flag bits, because the enum is packed into a bit field that only supports its defined range (Default through SkipAllNext).","triggerScenarios":"Assigning InheritanceBehavior = (InheritanceBehavior)someRawInt where the cast integer is negative or greater than (int)InheritanceBehavior.SkipAllNext.","commonSituations":"Persisting/reading the enum as an int from config, XAML, or serialization where a stale or hand-edited numeric value is cast blindly; off-by-one constants from another enum family.","solutions":["Validate the integer against Enum.IsDefined(typeof(InheritanceBehavior), v) before casting and assigning","Fix the persisted/configured numeric value to a defined enum member","Use enum.TryParse with the string name instead of raw integer casts"],"exampleFix":"// before\nvar v = (InheritanceBehavior)intFromConfig;\nelement.InheritanceBehavior = v; // throws for out-of-range ints\n\n// after\nif (Enum.IsDefined(typeof(InheritanceBehavior), intFromConfig))\n    element.InheritanceBehavior = (InheritanceBehavior)intFromConfig;\nelse\n    element.InheritanceBehavior = InheritanceBehavior.Default;","handlingStrategy":"validation","validationCode":"int raw = intFromConfig;\nif (!Enum.IsDefined(typeof(InheritanceBehavior), raw))\n    throw new ArgumentOutOfRangeException(nameof(raw), $\"{raw} is not a valid InheritanceBehavior\");\nelement.InheritanceBehavior = (InheritanceBehavior)raw;","typeGuard":"static bool IsValidInheritanceBehavior(int v) =>\n    v >= 0 && v <= (int)InheritanceBehavior.SkipAllNext;","tryCatchPattern":"try { element.InheritanceBehavior = (InheritanceBehavior)raw; }\ncatch (InvalidEnumArgumentException ex) { log.Error(\"Bad InheritanceBehavior value\", ex); }","preventionTips":["Never cast raw ints to InheritanceBehavior without Enum.IsDefined","Parse enum values by name with Enum.TryParse","Validate persisted values after upgrades of the framework"],"tags":["wpf","invalid-enum-value","argument-validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}