dotnet/wpf · error · MS.Internal.Security.RightsManagement.RightsManagementException

InvalidLicense

InvalidLicense

Error message

RightsManagementFailureCode.InvalidLicense

What it means

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.

Solutions

  1. Confirm the license was produced by a compatible XPS/WPF RightsManagement publisher and is not corrupted.
  2. Re-publish/re-issue the license from the original issuer with standard string-encoded attributes.
  3. Validate the UseLicense bytes parse as XML with expected attributes before binding (UseLicense constructor round-trip).
  4. Catch RightsManagementException(FailureCode.InvalidLicense) and treat the license as unusable.

Example fix

// before: assume attribute is a string
string val = ReadBoundLicenseString(queryHandle, "APPLICATION");

// after: verify the license parses before querying
var useLicense = new UseLicense(licenseBytes); // throws early on malformed license
string val = ReadBoundLicenseString(queryHandle, "APPLICATION");
Defensive patterns

Strategy: try-catch

Validate before calling

var xml = XDocument.Parse(useLicenseXml);
if (xml.Root == null || xml.Root.Name.LocalName != "QUERY")
    throw new InvalidDataException("License is not in the expected XPS RM schema.");

Try / catch

catch (RightsManagementException ex) when (ex.FailureCode == RightsManagementFailureCode.InvalidLicense) { /* treat license as unusable; re-acquire from server */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/c72a99a2d26aec5b. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Security/RightsManagement/ClientSession.cs:1142

        // Otherwise FxCop will complain: AvoidUncalledPrivateCode in the FREE built DLL.
#if DEBUG
        private static string GetBoundLicenseStringAttribute(
            SafeRightsManagementHandle queryHandle,
            string attributeType, 
            uint attributeIndex)
        {
            uint attributeSize = 0;
            byte[] dataBuffer = null;

            uint encodingType;

            int hr = SafeNativeMethods.DRMGetBoundLicenseAttribute(
                queryHandle, attributeType, attributeIndex, out encodingType, ref attributeSize, null);
            Errors.ThrowOnErrorCode(hr);

            if (encodingType != (uint)LicenseAttributeEncoding.String)
            {
                throw new RightsManagementException(RightsManagementFailureCode.InvalidLicense);
            }

            // this is the size of the null terminator so essentially this is an empty string
            if (attributeSize < 2)
                return null;

            checked
            {
                dataBuffer = new byte[(int)attributeSize];
            }

            hr = SafeNativeMethods.DRMGetBoundLicenseAttribute(
                queryHandle, attributeType, attributeIndex, out encodingType, ref attributeSize, dataBuffer);
            Errors.ThrowOnErrorCode(hr);

            // we need to truncate the last 2 bytes that have unicode 0 termination
            return Encoding.Unicode.GetString(dataBuffer, 0, dataBuffer.Length - 2);
        }

View on GitHub (pinned to 81131a70a4)