dotnet/wpf · error · InvalidOperationException

SR.RMProviderExceptionNoUseLicense

Error message

SR.RMProviderExceptionNoUseLicense

What it means

SaveUseLicense also requires a use license to have been acquired previously. If the provider's _useLicense is null (LoadUseLicense/AcquireUseLicense never ran or returned false), it throws RMProviderExceptionNoUseLicense.

Solutions

  1. Call AcquireUseLicense (or LoadUseLicense) and check it returned true before SaveUseLicense
  2. Handle acquisition failure: log/retry against the RM server instead of saving
  3. Reorder code so license acquisition always precedes saving

Example fix

// before
provider.AcquireUseLicense();
provider.SaveUseLicense(package);
// after
if (provider.AcquireUseLicense()) { provider.SaveUseLicense(package); }
Defensive patterns

Strategy: validation

Validate before calling

if (provider.IsProtected && provider.AcquireUseLicense()) { provider.SaveUseLicense(package); }

Try / catch

try { provider.SaveUseLicense(package); }
catch (InvalidOperationException) { /* use license was never acquired; acquire first */ }

Prevention

When it happens

Trigger: Calling SaveUseLicense on a protected package without a successful preceding LoadUseLicense/AcquireUseLicense, or after acquisition failed and returned false.

Common situations: Ignoring the boolean return of AcquireUseLicense; license server unreachable so acquisition silently failed; wrong call ordering (save before acquire).

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


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/RightsManagementProvider.cs:267

        return (useLicense != null);
    }

    /// <summary>
    /// Saves the current use license and embeds it in the package.
    /// This requires a use license to have been acquired.
    /// </summary>
    void IRightsManagementProvider.SaveUseLicense(EncryptedPackageEnvelope package)
    {                
        if (!IsProtected)
        {
            throw new InvalidOperationException(
                SR.RMProviderExceptionNoPackageToDecrypt);
        }

        if (_useLicense == null)
        {
            throw new InvalidOperationException(
                SR.RMProviderExceptionNoUseLicense);
        }

        if (AllowLicenseCaching)
        {
            Trace.SafeWrite(Trace.Rights, "Writing Use License to package.");

            // Attempt to write the acquired license back to the package
            if (package.FileOpenAccess != FileAccess.Read)
            {
                package.RightsManagementInformation.
                    SaveUseLicense(_user, _useLicense);
            }
        }
        else
        {            
            Trace.SafeWrite(Trace.Rights, "NOLICCACHE is set, not writing Use License to package.");
        }        

View on GitHub (pinned to 81131a70a4)