{"record":{"id":"ffb18e1f5c846437","repo":"dotnet/wpf","slug":"invalidlicense-ffb18e","errorCode":"InvalidLicense","errorMessage":"RightsManagementFailureCode.InvalidLicense","messagePattern":"RightsManagementFailureCode\\.InvalidLicense","errorType":"error_code","errorClass":"RightsManagementException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Security/RightsManagement/UseLicense.cs","lineNumber":34,"sourceCode":"        /// This constructor accepts the serialized form of a use license, and builds an instance of the classs based on that.\n        /// </summary>\n        public UseLicense(string useLicense)\n        {\n\n            ArgumentNullException.ThrowIfNull(useLicense);\n            _serializedUseLicense = useLicense;\n\n\n            /////////////////\n            // parse out the Content Id GUID\n            /////////////////\n            string contentId;\n            string contentIdType;\n            ClientSession.GetContentIdFromLicense(_serializedUseLicense, out contentId, out contentIdType);\n\n            if (contentId == null)\n            {\n                throw new RightsManagementException(RightsManagementFailureCode.InvalidLicense);\n            }\n            else\n            {\n                _contentId = new Guid(contentId);\n            }\n\n            /////////////////\n            // Get Owner information from the license\n            /////////////////\n            _owner = ClientSession.ExtractUserFromCertificateChain(_serializedUseLicense);\n\n            /////////////////\n            // Get ApplicationSpecific Data Dictionary\n            /////////////////\n            _applicationSpecificDataDictionary = new ReadOnlyDictionary <string, string>\n                    (ClientSession.ExtractApplicationSpecificDataFromLicense(_serializedUseLicense));\n        }\n","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Security/RightsManagement/UseLicense.cs#L16-L52","documentation":"The UseLicense(string) constructor extracts the Content Id GUID from the serialized use license. If ClientSession.GetContentIdFromLicense returns no content id, it throws RightsManagementException with FailureCode.InvalidLicense — the string is not a structurally valid use license (missing the required content-id element).","triggerScenarios":"Calling new UseLicense(serialized) with a corrupted, truncated, or re-encoded license string; passing a publish license instead of a use license; a license whose XML lacks the content-id element.","commonSituations":"Extracting the use license from an XPS/RM-protected document incorrectly; storage round-trip damaging the XML (encoding, trimming); server issuing non-standard licenses.","solutions":["Pass the exact use-license string obtained via PublishLicense.AcquireUse or from the protected document metadata, unmodified","Confirm the blob is a use license (contains issuance license / content-id), not a publish license","Re-acquire the use license from the publish license instead of relying on a stored copy if the stored copy fails to parse","Check the license XML for the content-id element before constructing UseLicense"],"exampleFix":"// before\nvar useLicense = new UseLicense(storedUseLicense);\n\n// after\nUseLicense useLicense;\ntry\n{\n    useLicense = new UseLicense(storedUseLicense);\n}\ncatch (RightsManagementException ex) when (ex.FailureCode == RightsManagementFailureCode.InvalidLicense)\n{\n    useLicense = publishLicense.AcquireUse(secureEnvironment); // re-acquire fresh copy\n}","handlingStrategy":"try-catch","validationCode":"if (string.IsNullOrWhiteSpace(useLicense))\n    throw new ArgumentException(\"Use license string is empty\", nameof(useLicense));\nif (!useLicense.Contains(\"mdsid\")) // content-id element expected in a valid use license\n    throw new InvalidDataException(\"Use license missing content id\");","typeGuard":"static bool LooksLikeUseLicense(string s) =>\n    !string.IsNullOrWhiteSpace(s) && s.TrimStart().StartsWith(\"<\") && s.Contains(\"mdsid\", StringComparison.OrdinalIgnoreCase);","tryCatchPattern":"try { var ul = new UseLicense(serialized); }\ncatch (RightsManagementException ex) when (ex.FailureCode == RightsManagementFailureCode.InvalidLicense)\n{\n    // stored copy is unusable — re-acquire from the publish license\n    var ul2 = publishLicense.AcquireUse(secureEnvironment);\n}","preventionTips":["Store the use license exactly as acquired; avoid encoding transformations","Prefer re-acquiring the use license over trusting long-lived stored copies","Keep publish and use license blobs in separate, labeled fields"],"tags":["rights-management","drm","license-parsing","wpf"],"backgroundTag":"schema-validation-failed","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"}