{"record":{"id":"9471c67281bf60df","repo":"dotnet/wpf","slug":"sr-format-sr-invalidauthenticationtypestring","errorCode":null,"errorMessage":"SR.Format(SR.InvalidAuthenticationTypeString, typePrefixedUserName)","messagePattern":"SR\\.Format\\(SR\\.InvalidAuthenticationTypeString, typePrefixedUserName\\)","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/RightsManagementEncryptionTransform.cs","lineNumber":1072,"sourceCode":"            // parameter.\n            int colonIndex = typePrefixedUserName.IndexOf(':');\n            if (colonIndex < 1 || colonIndex >= typePrefixedUserName.Length - 1)\n            {\n                throw new FileFormatException(SR.InvalidTypePrefixedUserName);\n            }\n\n            // No need to use checked{} here since colonIndex cannot be >= to (max int - 1)\n            userName = typePrefixedUserName.Substring(colonIndex + 1);\n\n            // Usernames: Case-Insensitive comparison\n            ReadOnlySpan<char> authenticationSpan = typePrefixedUserName.AsSpan(0, colonIndex);\n\n            if (authenticationSpan.Equals(nameof(AuthenticationType.Windows), StringComparison.OrdinalIgnoreCase))\n                authenticationType = AuthenticationType.Windows;\n            else if (authenticationSpan.Equals(nameof(AuthenticationType.Passport), StringComparison.OrdinalIgnoreCase))\n                authenticationType = AuthenticationType.Passport;\n            else // Didn't find a matching enumeration constant.\n                throw new FileFormatException(SR.Format(SR.InvalidAuthenticationTypeString, typePrefixedUserName));\n        }\n\n        /// <summary>\n        /// Load the use license from the specified stream.\n        /// </summary>\n        /// <param name=\"utf8Reader\">\n        /// The Utf 8 BinaryReader from which the use license is to be loaded.\n        /// </param>\n        /// <returns>\n        /// The use license from the stream.\n        /// </returns>\n        /// <remarks>\n        /// For details of the stream format, see the comments in LoadUseLicenseAndUserFromStream.\n        /// </remarks>\n        private UseLicense\n        LoadUseLicenseFromStream(\n            BinaryReader utf8Reader\n            )","sourceCodeStart":1054,"sourceCodeEnd":1090,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/RightsManagementEncryptionTransform.cs#L1054-L1090","documentation":"After splitting the type prefix, ParseTypePrefixedUserName matches it case-insensitively against AuthenticationType constants Windows and Passport. An unrecognized prefix throws FileFormatException with SR.InvalidAuthenticationTypeString formatted with the full type-prefixed user name.","triggerScenarios":"Reading a use-license stream whose user name prefix is neither 'windows' nor 'passport' (case-insensitive), e.g. 'liveid:...' or a misspelled prefix like 'windws:'.","commonSituations":"Documents produced by third-party RM writers using other auth schemes; typos when constructing ContentUser names manually; format evolution between RM implementations.","solutions":["Change the prefix to 'windows' or 'passport' to match AuthenticationType constants","Rebuild the ContentUser with AuthenticationType.Windows or AuthenticationType.Passport so the correct prefix is stored","Regenerate/re-save the document from the original RM writer","Catch FileFormatException to report the unsupported authentication scheme gracefully"],"exampleFix":"// before\nvar user = new ContentUser(\"liveid:foo@bar.com\", AuthenticationType.Windows);\n// after\nvar user = new ContentUser(\"passport:foo@hotmail.com\", AuthenticationType.Passport);","handlingStrategy":"try-catch","validationCode":"static bool IsSupportedAuthPrefix(string s) { int i = s.IndexOf(':'); var p = i > 0 ? s.Substring(0, i) : \"\"; return p.Equals(\"Windows\", StringComparison.OrdinalIgnoreCase) || p.Equals(\"Passport\", StringComparison.OrdinalIgnoreCase); }","typeGuard":"bool HasSupportedAuthenticationType(string typePrefixedUserName) { var prefix = typePrefixedUserName.Split(':')[0]; return prefix.Equals(nameof(AuthenticationType.Windows), StringComparison.OrdinalIgnoreCase) || prefix.Equals(nameof(AuthenticationType.Passport), StringComparison.OrdinalIgnoreCase); }","tryCatchPattern":"try { ParseTypePrefixedUserName(raw, out _, out _); } catch (FileFormatException ex) { /* unsupported auth prefix: report unsupported scheme */ }","preventionTips":["Use only AuthenticationType.Windows or AuthenticationType.Passport when constructing users","Avoid third-party auth prefixes not understood by WPF RM","Normalize case is fine (comparison is case-insensitive) but spelling must match the enum names"],"tags":["wpf","rights-management","file-format","authentication","enum"],"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"}