{"record":{"id":"c36ebae40236ce2f","repo":"dotnet/wpf","slug":"argumentoutofrangeexception-right","errorCode":null,"errorMessage":"ArgumentOutOfRangeException(right)","messagePattern":"ArgumentOutOfRangeException\\(right\\)","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Security/RightsManagement/Grant.cs","lineNumber":44,"sourceCode":"            // Add validation here \n\n            ArgumentNullException.ThrowIfNull(user);\n\n            if ((right != ContentRight.View) && \n                (right != ContentRight.Edit) && \n                (right != ContentRight.Print) && \n                (right != ContentRight.Extract) && \n                (right != ContentRight.ObjectModel) && \n                (right != ContentRight.Owner) && \n                (right != ContentRight.ViewRightsData) && \n                (right != ContentRight.Forward) && \n                (right != ContentRight.Reply) &&\n                (right != ContentRight.ReplyAll) &&\n                (right != ContentRight.Sign) &&\n                (right != ContentRight.DocumentEdit)  &&\n                (right != ContentRight.Export))\n            {\n                throw new ArgumentOutOfRangeException(nameof(right));                \n            }\n\n            ArgumentOutOfRangeException.ThrowIfGreaterThan(validFrom, validUntil);\n\n            _user = user;\n            _right = right;\n\n            _validFrom = validFrom;\n            _validUntil = validUntil;\n        }\n\n\n\n        /// <summary>\n        /// Read only User propery.\n        /// </summary>\n        public ContentUser User\n        {","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Security/RightsManagement/Grant.cs#L26-L62","documentation":"The ContentGrant constructor validates the right parameter against the supported ContentRight values (View, Edit, Print, Forward, Reply, ReplyAll, Sign, DocumentEdit, Export, and Owner per the guard chain) and throws ArgumentOutOfRangeException(nameof(right)) when the value is not one of them. This guards against undefined enum values leaking into the rights-management grant model.","triggerScenarios":"Constructing new ContentGrant(user, right) with an undefined or uncast ContentRight value, e.g. (ContentRight)999 or a right obtained from an unvalidated external source.","commonSituations":"Deserializing rights from config/database as int and casting to ContentRight; version mismatch where a newer enum member is passed to an older library; copy-paste of an incorrect enum type with coincident numeric values.","solutions":["Pass only defined ContentRight members from the supported set","Validate the value with Enum.IsDefined (and membership in the supported subset) before constructing ContentGrant","Fix deserialization code to map/whitelist int values to valid ContentRights","If a newer right is needed, use a library/runtime version that defines it"],"exampleFix":"// before\nvar grant = new ContentGrant(user, (ContentRight)rawInt); // throws for undefined values\n// after\nif (!Enum.IsDefined(typeof(ContentRight), rawInt))\n    throw new ArgumentException($\"Unsupported right: {rawInt}\");\nvar grant = new ContentGrant(user, (ContentRight)rawInt);","handlingStrategy":"validation","validationCode":"static readonly HashSet<ContentRight> Supported = new()\n    { ContentRight.View, ContentRight.Edit, ContentRight.Print, ContentRight.Forward,\n      ContentRight.Reply, ContentRight.ReplyAll, ContentRight.Sign,\n      ContentRight.DocumentEdit, ContentRight.Export };\nbool IsValidRight(ContentRight r) => Supported.Contains(r);","typeGuard":"bool IsDefinedContentRight(object value) =>\n    value is ContentRight r && Enum.IsDefined(typeof(ContentRight), r);","tryCatchPattern":"try { var grant = new ContentGrant(user, right); }\ncatch (ArgumentOutOfRangeException)\n{ /* map to a supported right or reject input */ }","preventionTips":["Whitelist ContentRight values before casting from ints/strings","Keep library and runtime versions aligned with the enum set used","Sanitize externally sourced right identifiers at deserialization"],"tags":["drm","rights-management","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-22T01:17:13.364Z"}