{"record":{"id":"6088e5fb703febb4","repo":"dotnet/wpf","slug":"argumentoutofrangeexception-authenticationtype","errorCode":null,"errorMessage":"ArgumentOutOfRangeException(authenticationType)","messagePattern":"ArgumentOutOfRangeException\\(authenticationType\\)","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Security/RightsManagement/User.cs","lineNumber":34,"sourceCode":"        ///  This constructor creates a user that will be granted a right. Or used in other related scenarios like\n        /// initializing secure environment for the user, or enumerating rights granted to various users.         \n        /// </summary>\n        public ContentUser(string name, AuthenticationType authenticationType)\n        {\n\n            ArgumentNullException.ThrowIfNull(name);\n\n            if (name.Trim().Length == 0)\n            {\n                throw new ArgumentOutOfRangeException(nameof(name));\n            }\n\n            if ((authenticationType != AuthenticationType.Windows) &&\n                (authenticationType != AuthenticationType.Passport) &&\n                (authenticationType != AuthenticationType.WindowsPassport) &&\n                (authenticationType != AuthenticationType.Internal))\n            {\n                throw new ArgumentOutOfRangeException(nameof(authenticationType));\n            }\n\n            // We only support Anyone for the internal mode at the moment\n            if (authenticationType == AuthenticationType.Internal)\n            {\n                if (!CompareToAnyone(name) && !CompareToOwner(name))\n                {\n                    // we only support Anyone as internal user \n                    throw new ArgumentOutOfRangeException(nameof(name));\n                }\n            }\n\n            _name = name;\n            _authenticationType = authenticationType;\n        }\n\n        /// <summary>\n        /// Currently only 2 Authentication types supported Windows and Passport","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Security/RightsManagement/User.cs#L16-L52","documentation":"The ContentUser constructor in WPF's Rights Management (IRM) API throws ArgumentOutOfRangeException when authenticationType is not one of the four supported AuthenticationType values: Windows, Passport, WindowsPassport, or Internal. The API validates enum input eagerly rather than accepting arbitrary enum casts, since .NET enums can hold any underlying integer.","triggerScenarios":"Calling new ContentUser(name, (AuthenticationType)someInt) with an int that is not a defined AuthenticationType member; passing a default(AuthenticationType) value of 0 if it is not a defined member; casting between unrelated enum types.","commonSituations":"Persisting an AuthenticationType to a database or config as an int and casting it back after the enum definition changed; deserializing user records authored by a different library version; passing null-boxed or invalid enum values from external data.","solutions":["Pass a literal AuthenticationType enum member (Windows, Passport, WindowsPassport, or Internal) instead of a cast integer.","Validate the incoming value with Enum.IsDefined(typeof(AuthenticationType), value) before constructing ContentUser.","Check persisted data/config for stale or out-of-range integer values that no longer map to a defined enum member."],"exampleFix":"// before\nvar user = new ContentUser(name, (AuthenticationType)storedValue);\n// after\nif (!Enum.IsDefined(typeof(AuthenticationType), storedValue))\n    throw new InvalidOperationException($\"Unknown AuthenticationType: {storedValue}\");\nvar user = new ContentUser(name, (AuthenticationType)storedValue);","handlingStrategy":"validation","validationCode":"bool IsValidAuthType(AuthenticationType t) =>\n    t == AuthenticationType.Windows || t == AuthenticationType.Passport ||\n    t == AuthenticationType.WindowsPassport || t == AuthenticationType.Internal;","typeGuard":"bool IsDefinedAuthenticationType(object v, out AuthenticationType t)\n{\n    t = default;\n    return v is AuthenticationType a && Enum.IsDefined(typeof(AuthenticationType), a) && (t = a) == a;\n}","tryCatchPattern":"try { var user = new ContentUser(name, authType); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"authenticationType\")\n{\n    log.LogError($\"Unsupported AuthenticationType: {authType}\");\n}","preventionTips":["Only pass literal AuthenticationType members, never raw ints.","Validate with Enum.IsDefined before constructing.","Never persist enums as unchecked integers without a read-back validation."],"tags":["argument-out-of-range","enum","rights-management","wpf"],"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"}