dotnet/wpf · error · RightsManagementException

InvalidLicense

InvalidLicense

Error message

RightsManagementFailureCode.InvalidLicense

What it means

The PublishLicense(string) constructor parses a serialized signed publish license and requires a valid Use License acquisition URI inside it. When the underlying RM SDK (msdrm) cannot extract the acquisition URI from the license blob, the constructor throws RightsManagementException with FailureCode.InvalidLicense, meaning the license string is malformed, truncated, or not a genuinely signed publish license.

Solutions

  1. Verify the string is the exact output of UnsignedPublishLicense.Sign (or the publisher's original) with no re-encoding or trimming
  2. Confirm the string is a publish license, not a use license — use UseLicense for the use-license blob
  3. Round-trip test: new PublishLicense(new UnsignedPublishLicense(...).Sign(secureEnvironment).ToString()) to confirm the blob itself is valid
  4. Inspect the license XML: it must contain the Work/OFFICIAL resource with a valid use-license-acquisition-url element

Example fix

// before
var publishLicense = new PublishLicense(config.AppSettings["License"]);

// after
string raw = config.AppSettings["License"];
if (string.IsNullOrWhiteSpace(raw) || !raw.Contains("<WORK"))
    throw new InvalidOperationException("Stored publish license is missing or malformed");
var publishLicense = new PublishLicense(raw);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(signedPublishLicense))
    throw new ArgumentException("Publish license string is empty", nameof(signedPublishLicense));
// the signed publish license is XML; a valid one embeds an acquisition URL
if (!signedPublishLicense.Contains("use-license-acquisition-url"))
    throw new InvalidDataException("License has no use-license acquisition URL; not a valid signed publish license");

Type guard

static bool IsValidPublishLicense(string s) =>
    !string.IsNullOrWhiteSpace(s) && s.TrimStart().StartsWith("<") && s.Contains("use-license-acquisition-url");

Try / catch

try { var pl = new PublishLicense(serialized); }
catch (RightsManagementException ex) when (ex.FailureCode == RightsManagementFailureCode.InvalidLicense)
{
    // re-obtain or re-sign the license; do not retry the same blob
    logger.LogError(ex, "Publish license blob is invalid");
    throw new InvalidLicenseException("Publish license malformed — republish the document", ex);
}

Prevention

When it happens

Trigger: Calling new PublishLicense(serialized) where the string was corrupted in transit/storage, was never produced by UnsignedPublishLicense.Sign, contains extra whitespace/encoding changes (e.g. XML-escaped or line-wrapped), or is a Use License passed in by mistake instead of a Publish License.

Common situations: Storing the license in a database/config and losing characters to encoding; copying the license out of an XPS/protected document incorrectly; hand-editing the XML; mixing up UseLicense and PublishLicense strings when persisting both.

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/230a423d7462a41a. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Security/RightsManagement/PublishLicense.cs:36

        /// This constructor accepts a string representation of a Publish License, which is supposed to be proided by the 
        /// publisher of a document to tyhe consumer of a document. 
        /// </summary>
        public PublishLicense(string signedPublishLicense)
        {

            ArgumentNullException.ThrowIfNull(signedPublishLicense);

            _serializedPublishLicense = signedPublishLicense;

            /////////////////
            // parse out the Use License acquisition Url 
            /////////////////
            _useLicenseAcquisitionUriFromPublishLicense =
                    ClientSession.GetUseLicenseAcquisitionUriFromPublishLicense(_serializedPublishLicense);

            if (_useLicenseAcquisitionUriFromPublishLicense == null)
            {
                throw new RightsManagementException(RightsManagementFailureCode.InvalidLicense);
            }


            /////////////////
            // parse out the Content Id GUID 
            /////////////////
            String contentIdStr = ClientSession.GetContentIdFromPublishLicense(_serializedPublishLicense);

            if (contentIdStr == null)
            {
                throw new RightsManagementException(RightsManagementFailureCode.InvalidLicense);                
            }
            else
            {
                _contentId = new Guid(contentIdStr);
            }

            /////////////////

View on GitHub (pinned to 81131a70a4)