{"record":{"id":"09c5065b9ff488c7","repo":"dotnet/wpf","slug":"invalidenumargumentexception-param-edge-elementedge","errorCode":null,"errorMessage":"InvalidEnumArgumentException(param, edge, ElementEdge)","messagePattern":"InvalidEnumArgumentException\\(param, edge, ElementEdge\\)","errorType":"validation","errorClass":"InvalidEnumArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ValidationHelper.cs","lineNumber":85,"sourceCode":"        // Throws an ArgumentException if direction is not a valid enum.\n        internal static void VerifyDirection(LogicalDirection direction, string argumentName)\n        {\n            if (direction != LogicalDirection.Forward &&\n                direction != LogicalDirection.Backward)\n            {\n                throw new InvalidEnumArgumentException(argumentName, (int)direction, typeof(LogicalDirection));\n            }\n        }\n\n        // Throws an ArgumentException if edge is not a valid enum.\n        internal static void VerifyElementEdge(ElementEdge edge, string param)\n        {\n            if (edge != ElementEdge.BeforeStart &&\n                edge != ElementEdge.AfterStart  &&\n                edge != ElementEdge.BeforeEnd   &&\n                edge != ElementEdge.AfterEnd)\n            {\n                throw new InvalidEnumArgumentException(param, (int)edge, typeof(ElementEdge));\n            }\n        }\n\n        // ...............................................................\n        //\n        // TextSchema Validation\n        //\n        // ...............................................................\n\n        // Checks whether it is valid to insert the child object at passed position.\n        internal static void ValidateChild(TextPointer position, object child, string paramName)\n        {\n            Invariant.Assert(position != null);\n\n            if (child == null)\n            {\n                throw new ArgumentNullException(paramName);\n            }","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ValidationHelper.cs#L67-L103","documentation":"ValidationHelper.VerifyElementEdge throws InvalidEnumArgumentException when the supplied ElementEdge is not one of BeforeStart, AfterStart, BeforeEnd, AfterEnd. ElementEdge is a four-value enum; any other value is an invalid enum argument.","triggerScenarios":"Passing an ElementEdge produced by an unchecked int cast or bad data to APIs taking a 'param' element edge, e.g. TextElement positioning helpers.","commonSituations":"Restoring persisted insertion-edge values from disk or interop without validation; mixing up a different WPF enum with ElementEdge.","solutions":["Pass one of the four valid ElementEdge members.","Validate raw ints with Enum.IsDefined(typeof(ElementEdge), value) before casting.","Fix interop/marshalling code that misnumbers the enum."],"exampleFix":"// before\nvar edge = (ElementEdge)savedInt;\n// after\nif (!Enum.IsDefined(typeof(ElementEdge), savedInt)) throw new InvalidDataException(\"bad edge\");\nvar edge = (ElementEdge)savedInt;","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(ElementEdge), value)) throw new InvalidEnumArgumentException(nameof(value), value, typeof(ElementEdge));","typeGuard":"bool IsValidElementEdge(object v) => v is ElementEdge e && (e == ElementEdge.BeforeStart || e == ElementEdge.AfterStart || e == ElementEdge.BeforeEnd || e == ElementEdge.AfterEnd);","tryCatchPattern":"try { ... } catch (InvalidEnumArgumentException ex) { /* default to a valid edge */ }","preventionTips":["Keep ElementEdge values in strongly typed variables, not ints","Validate marshalled/interop values before passing to text APIs"],"tags":["wpf","enum","invalid-enum-argument"],"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-21T21:30:21.729Z"}