{"record":{"id":"73473abce9082390","repo":"dotnet/wpf","slug":"sr-rmproviderexceptionnouselicense","errorCode":null,"errorMessage":"SR.RMProviderExceptionNoUseLicense","messagePattern":"SR\\.RMProviderExceptionNoUseLicense","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/RightsManagementProvider.cs","lineNumber":267,"sourceCode":"\n        return (useLicense != null);\n    }\n\n    /// <summary>\n    /// Saves the current use license and embeds it in the package.\n    /// This requires a use license to have been acquired.\n    /// </summary>\n    void IRightsManagementProvider.SaveUseLicense(EncryptedPackageEnvelope package)\n    {                \n        if (!IsProtected)\n        {\n            throw new InvalidOperationException(\n                SR.RMProviderExceptionNoPackageToDecrypt);\n        }\n\n        if (_useLicense == null)\n        {\n            throw new InvalidOperationException(\n                SR.RMProviderExceptionNoUseLicense);\n        }\n\n        if (AllowLicenseCaching)\n        {\n            Trace.SafeWrite(Trace.Rights, \"Writing Use License to package.\");\n\n            // Attempt to write the acquired license back to the package\n            if (package.FileOpenAccess != FileAccess.Read)\n            {\n                package.RightsManagementInformation.\n                    SaveUseLicense(_user, _useLicense);\n            }\n        }\n        else\n        {            \n            Trace.SafeWrite(Trace.Rights, \"NOLICCACHE is set, not writing Use License to package.\");\n        }        ","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/RightsManagementProvider.cs#L249-L285","documentation":"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.","triggerScenarios":"Calling SaveUseLicense on a protected package without a successful preceding LoadUseLicense/AcquireUseLicense, or after acquisition failed and returned false.","commonSituations":"Ignoring the boolean return of AcquireUseLicense; license server unreachable so acquisition silently failed; wrong call ordering (save before acquire).","solutions":["Call AcquireUseLicense (or LoadUseLicense) and check it returned true before SaveUseLicense","Handle acquisition failure: log/retry against the RM server instead of saving","Reorder code so license acquisition always precedes saving"],"exampleFix":"// before\nprovider.AcquireUseLicense();\nprovider.SaveUseLicense(package);\n// after\nif (provider.AcquireUseLicense()) { provider.SaveUseLicense(package); }","handlingStrategy":"validation","validationCode":"if (provider.IsProtected && provider.AcquireUseLicense()) { provider.SaveUseLicense(package); }","typeGuard":null,"tryCatchPattern":"try { provider.SaveUseLicense(package); }\ncatch (InvalidOperationException) { /* use license was never acquired; acquire first */ }","preventionTips":["Check the boolean result of AcquireUseLicense before saving","Retry license acquisition on transient RM server failures","Enforce call order: acquire -> save"],"tags":["rights-management","missing-license","call-order"],"backgroundTag":"invalid-state-transition","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}