dotnet/wpf · error · InvalidOperationException
SR.RMProviderExceptionNoPackageToDecrypt
Error message
SR.RMProviderExceptionNoPackageToDecrypt
What it means
IRightsManagementProvider.LoadUseLicense requires the provider to be wrapping an encrypted (RM-protected) package. When IsProtected is false there is no package to decrypt a use license from, so an InvalidOperationException with RMProviderExceptionNoPackageToDecrypt is thrown.
Solutions
- Only call LoadUseLicense after IsProtected returns true
- Load/attach the EncryptedPackageEnvelope first, or use the non-interface LoadUseLicense path appropriate for unprotected content
- Guard with a check like if (provider.IsProtected) before calling license methods
Example fix
// before bool loaded = provider.LoadUseLicense(); // after bool loaded = provider.IsProtected ? provider.LoadUseLicense() : false;
Defensive patterns
Strategy: validation
Validate before calling
if (provider.IsProtected) { provider.LoadUseLicense(); } Type guard
bool CanLoadLicense(IRightsManagementProvider p) => p is { IsProtected: true }; Try / catch
try { provider.LoadUseLicense(); }
catch (InvalidOperationException) { /* not a protected package; handle unprotected path */ } Prevention
- Always check IsProtected before RM license APIs
- Structure RM steps behind a single guarded entry point
- Validate the package is encrypted before handing it to the provider
When it happens
Trigger: Explicitly calling LoadUseLicense (via IRightsManagementProvider) on a provider whose _encryptedPackageEnvelope is null or unprotected.
Common situations: Calling license APIs before attaching/opening an encrypted package; passing an unencrypted XPS to RM tooling; provider constructed but no package loaded yet.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- ArgumentOutOfRangeException(authentication)
- ArgumentOutOfRangeException(authenticationType)
- ArgumentOutOfRangeException(name)
- ArgumentOutOfRangeException(right)
- ArgumentOutOfRangeException(user)
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/34539abc79a73ac0.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/RightsManagementProvider.cs:193
Trace.SafeWriteIf(
(_secureEnvironment != null),
Trace.Rights,
"SecureEnvironment was initialized for a specific user.");
SetUserFromSecureEnvironment();
}
/// <summary>
/// Loads a use license for the user from the package.
/// This requires InitializeEnvironment to have been called.
/// </summary>
/// <returns>Whether or not a use license could be loaded directly from the
/// package</returns>
bool IRightsManagementProvider.LoadUseLicense()
{
if (!IsProtected)
{
throw new InvalidOperationException(
SR.RMProviderExceptionNoPackageToDecrypt);
}
UseLicense useLicense;
useLicense = _encryptedPackageEnvelope
.RightsManagementInformation.LoadUseLicense(_user);
if (useLicense != null)
{
Trace.SafeWrite(Trace.Rights, "Existing use license was found.");
_useLicense = useLicense;
}
return (useLicense != null);
}
/// <summary>View on GitHub (pinned to 81131a70a4)