dotnet/wpf · error · RightsManagementException
InvalidLicense
InvalidLicense
Error message
RightsManagementFailureCode.InvalidLicense
What it means
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).
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
Example fix
// before
var useLicense = new UseLicense(storedUseLicense);
// after
UseLicense useLicense;
try
{
useLicense = new UseLicense(storedUseLicense);
}
catch (RightsManagementException ex) when (ex.FailureCode == RightsManagementFailureCode.InvalidLicense)
{
useLicense = publishLicense.AcquireUse(secureEnvironment); // re-acquire fresh copy
} Defensive patterns
Strategy: try-catch
Validate before calling
if (string.IsNullOrWhiteSpace(useLicense))
throw new ArgumentException("Use license string is empty", nameof(useLicense));
if (!useLicense.Contains("mdsid")) // content-id element expected in a valid use license
throw new InvalidDataException("Use license missing content id"); Type guard
static bool LooksLikeUseLicense(string s) =>
!string.IsNullOrWhiteSpace(s) && s.TrimStart().StartsWith("<") && s.Contains("mdsid", StringComparison.OrdinalIgnoreCase); Try / catch
try { var ul = new UseLicense(serialized); }
catch (RightsManagementException ex) when (ex.FailureCode == RightsManagementFailureCode.InvalidLicense)
{
// stored copy is unusable — re-acquire from the publish license
var ul2 = publishLicense.AcquireUse(secureEnvironment);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Extracting the use license from an XPS/RM-protected document incorrectly; storage round-trip damaging the XML (encoding, trimming); server issuing non-standard licenses.
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
- InvalidLicense
- NeedsGroupIdentityActivation
- SR.RightsManagementExceptionNoRightsForOperation
- SR.XpsViewerRightsManagementException
- ArgumentOutOfRangeException(authentication)
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/ffb18e1f5c846437.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Security/RightsManagement/UseLicense.cs:34
/// This constructor accepts the serialized form of a use license, and builds an instance of the classs based on that.
/// </summary>
public UseLicense(string useLicense)
{
ArgumentNullException.ThrowIfNull(useLicense);
_serializedUseLicense = useLicense;
/////////////////
// parse out the Content Id GUID
/////////////////
string contentId;
string contentIdType;
ClientSession.GetContentIdFromLicense(_serializedUseLicense, out contentId, out contentIdType);
if (contentId == null)
{
throw new RightsManagementException(RightsManagementFailureCode.InvalidLicense);
}
else
{
_contentId = new Guid(contentId);
}
/////////////////
// Get Owner information from the license
/////////////////
_owner = ClientSession.ExtractUserFromCertificateChain(_serializedUseLicense);
/////////////////
// Get ApplicationSpecific Data Dictionary
/////////////////
_applicationSpecificDataDictionary = new ReadOnlyDictionary <string, string>
(ClientSession.ExtractApplicationSpecificDataFromLicense(_serializedUseLicense));
}
View on GitHub (pinned to 81131a70a4)