{"record":{"id":"c3369a58275ad10e","repo":"dotnet/wpf","slug":"sr-invalidtypeprefixedusername","errorCode":null,"errorMessage":"SR.InvalidTypePrefixedUserName","messagePattern":"SR\\.InvalidTypePrefixedUserName","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/RightsManagementEncryptionTransform.cs","lineNumber":1058,"sourceCode":"        /// <param name=\"typePrefixedUserName\">\n        /// The string to be parsed.\n        /// </param>\n        /// <param name=\"authenticationType\">\n        /// Specifies whether the string represents a Windows or Passport user ID.\n        /// </param>\n        /// <param name=\"userName\">\n        /// The user's ID.\n        /// </param>\n        private static void ParseTypePrefixedUserName(string typePrefixedUserName, out AuthenticationType authenticationType, out string userName)\n        {\n            // We don't actually know the authentication type yet, and we might find that\n            // the type-prefixed user name doesn't even specify a valid authentication\n            // type. But we have to assign to authenticationType because it's an out\n            // 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.","sourceCodeStart":1040,"sourceCodeEnd":1076,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/RightsManagementEncryptionTransform.cs#L1040-L1076","documentation":"ParseTypePrefixedUserName splits strings like \"windows:DOMAIN\\\\alias\" on the first ':'. It throws FileFormatException with SR.InvalidTypePrefixedUserName when there is no colon, or nothing before/after it, so the string is not a valid type-prefixed user name stored in the use-license stream.","triggerScenarios":"Loading a use license whose embedded user name lacks the 'type:' prefix, has an empty type, or an empty user name (colon at index 0 or at the end of the string).","commonSituations":"Corrupted or hand-crafted protected documents; strings built without the prefix (plain 'user@domain.com'); stream data written by a buggy or non-WPF RM writer.","solutions":["Rebuild the user name string as \"windows:DOMAIN\\\\alias\" or \"passport:user@hotmail.com\" format","Regenerate the protected document to restore a valid stored user name","Validate the type-prefixed format (non-empty prefix and name around a colon) before persisting","Catch FileFormatException and treat the document's use license as invalid"],"exampleFix":"// before\nstring userName = \"DOMAIN\\\\alias\"; // missing type prefix\n// after\nstring userName = \"windows:DOMAIN\\\\alias\";","handlingStrategy":"try-catch","validationCode":"static bool IsTypePrefixedUserName(string s) { int i = s?.IndexOf(':') ?? -1; return i > 0 && i < s.Length - 1; }","typeGuard":"bool IsValidTypePrefixedUserName(string s) { if (string.IsNullOrEmpty(s)) return false; int i = s.IndexOf(':'); return i > 0 && i < s.Length - 1; }","tryCatchPattern":"try { ParseTypePrefixedUserName(raw); } catch (FileFormatException) { /* invalid stored user name: regenerate or ignore entry */ }","preventionTips":["Always store user names with a type prefix ('windows:...' or 'passport:...')","Never write bare user names into use-license streams","Validate format before persisting license data"],"tags":["wpf","rights-management","file-format","parsing"],"backgroundTag":"invalid-identifier-format","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"}