{"record":{"id":"c72a99a2d26aec5b","repo":"dotnet/wpf","slug":"invalidlicense","errorCode":"InvalidLicense","errorMessage":"RightsManagementFailureCode.InvalidLicense","messagePattern":"RightsManagementFailureCode\\.InvalidLicense","errorType":"error_code","errorClass":"MS.Internal.Security.RightsManagement.RightsManagementException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Security/RightsManagement/ClientSession.cs","lineNumber":1142,"sourceCode":"        // Otherwise FxCop will complain: AvoidUncalledPrivateCode in the FREE built DLL.\n#if DEBUG\n        private static string GetBoundLicenseStringAttribute(\n            SafeRightsManagementHandle queryHandle,\n            string attributeType, \n            uint attributeIndex)\n        {\n            uint attributeSize = 0;\n            byte[] dataBuffer = null;\n\n            uint encodingType;\n\n            int hr = SafeNativeMethods.DRMGetBoundLicenseAttribute(\n                queryHandle, attributeType, attributeIndex, out encodingType, ref attributeSize, null);\n            Errors.ThrowOnErrorCode(hr);\n\n            if (encodingType != (uint)LicenseAttributeEncoding.String)\n            {\n                throw new RightsManagementException(RightsManagementFailureCode.InvalidLicense);\n            }\n\n            // this is the size of the null terminator so essentially this is an empty string\n            if (attributeSize < 2)\n                return null;\n\n            checked\n            {\n                dataBuffer = new byte[(int)attributeSize];\n            }\n\n            hr = SafeNativeMethods.DRMGetBoundLicenseAttribute(\n                queryHandle, attributeType, attributeIndex, out encodingType, ref attributeSize, dataBuffer);\n            Errors.ThrowOnErrorCode(hr);\n\n            // we need to truncate the last 2 bytes that have unicode 0 termination\n            return Encoding.Unicode.GetString(dataBuffer, 0, dataBuffer.Length - 2);\n        }","sourceCodeStart":1124,"sourceCodeEnd":1160,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Security/RightsManagement/ClientSession.cs#L1124-L1160","documentation":"When reading a string attribute from a bound license, the library checks the encoding type returned by native DRMGetBoundLicenseAttribute. If the attribute's encoding is not LicenseAttributeEncoding.String, the license content does not match the expected schema and it throws RightsManagementException with failure code InvalidLicense.","triggerScenarios":"Calling GetBoundLicenseStringAttribute-style internal queries (used by UseLicense/ContentUser parsing, e.g. reading the APPLICATION or USER attributes) on a license whose attribute is encoded differently than expected.","commonSituations":"Consuming a license produced by a non-WPF/non-XPS RMS tool with divergent attribute encodings; hand-crafted or corrupted license files; version drift between the license issuer and the .NET RightsManagement wrapper.","solutions":["Confirm the license was produced by a compatible XPS/WPF RightsManagement publisher and is not corrupted.","Re-publish/re-issue the license from the original issuer with standard string-encoded attributes.","Validate the UseLicense bytes parse as XML with expected attributes before binding (UseLicense constructor round-trip).","Catch RightsManagementException(FailureCode.InvalidLicense) and treat the license as unusable."],"exampleFix":"// before: assume attribute is a string\nstring val = ReadBoundLicenseString(queryHandle, \"APPLICATION\");\n\n// after: verify the license parses before querying\nvar useLicense = new UseLicense(licenseBytes); // throws early on malformed license\nstring val = ReadBoundLicenseString(queryHandle, \"APPLICATION\");","handlingStrategy":"try-catch","validationCode":"var xml = XDocument.Parse(useLicenseXml);\nif (xml.Root == null || xml.Root.Name.LocalName != \"QUERY\")\n    throw new InvalidDataException(\"License is not in the expected XPS RM schema.\");","typeGuard":null,"tryCatchPattern":"catch (RightsManagementException ex) when (ex.FailureCode == RightsManagementFailureCode.InvalidLicense) { /* treat license as unusable; re-acquire from server */ }","preventionTips":["Only consume licenses produced by the standard XPS/WPF RM pipeline.","Validate license XML structure before binding.","Keep publisher and consumer framework versions aligned."],"tags":["rights-management","drm","license","schema"],"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"}