{"record":{"id":"93ab61934a5d20c1","repo":"dotnet/wpf","slug":"sr-xpsviewerrightsmanagementexception-93ab61","errorCode":null,"errorMessage":"SR.XpsViewerRightsManagementException","messagePattern":"SR\\.XpsViewerRightsManagementException","errorType":"exception","errorClass":"XpsViewerException","httpStatus":null,"severity":"critical","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/RightsManagementManager.cs","lineNumber":210,"sourceCode":"        internal void SetEncryptedPackage(EncryptedPackageEnvelope newPackage)\n        {\n            bool publishLicenseChanged = true;\n\n            try\n            {\n                _rmProvider.SetEncryptedPackage(\n                    newPackage,\n                    out publishLicenseChanged);\n            }\n            catch (RightsManagementException exception)\n            {\n                RightsManagementErrorHandler.HandleOrRethrowException(\n                    RightsManagementOperation.Decrypt,\n                    exception);\n\n                // On an exception here we can't continue; rethrow it in an\n                // XPSViewer exception\n                throw new XpsViewerException(\n                    SR.XpsViewerRightsManagementException,\n                    exception);\n            }\n\n            if (_rmProvider.IsProtected)\n            {\n                // Get a use license for the new package\n                RightsManagementLicense license = GetUseLicense();\n\n                if (license == null ||\n                    !license.HasPermission(RightsManagementPermissions.AllowView))\n                {\n                    throw new XpsViewerException(\n                        SR.RMProviderExceptionNoRightsToDocument);\n                }\n            }\n\n            if (publishLicenseChanged)","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/RightsManagementManager.cs#L192-L228","documentation":"RightsManagementManager.SetEncryptedPackage decrypts a rights-managed XPS package; when decryption throws, RightsManagementErrorHandler.HandleOrRethrowException runs first, then the code unconditionally rethrows the exception wrapped in XpsViewerException(SR.XpsViewerRightsManagementException). This is the XPS Viewer's generic wrapper for rights-management failures during package decryption.","triggerScenarios":"Opening a protected XPS document where SetEncryptedPackage's Decrypt operation fails — missing/invalid use license, unreachable RMS server, corrupt encrypted package, or expired credentials.","commonSituations":"User without a valid license opens an RM-protected XPS; RMS server unreachable/offline; client machine lacks RMS initialization; document encrypted with keys the current account cannot obtain.","solutions":["Inspect the InnerException (the original rights-management exception) to find the root cause; fix that underlying RMS condition.","Verify RMS service connectivity and that the user can acquire a use license (open the document via a known-good client to test).","Re-acquire credentials/use license (re-activate the RMS client, sign in with the entitled account).","Catch XpsViewerException around document open and show a friendly 'cannot open protected document' message with inner details for support."],"exampleFix":"// before\nxpsViewer.Open(docPath); // throws XpsViewerException wrapping RMS failure\n// after\ntry { xpsViewer.Open(docPath); }\ncatch (XpsViewerException ex)\n{\n    ShowRmsError(ex.InnerException); // e.g. license expired / server unreachable\n}","handlingStrategy":"try-catch","validationCode":"// Pre-check: can the current user acquire a use license for this document?\n// Open a trial SecureEnvironment / query RM enabler before loading the document.","typeGuard":null,"tryCatchPattern":"try { manager.SetEncryptedPackage(packageStream); }\ncatch (XpsViewerException ex)\n{ HandleRmFailure(ex.InnerException); // license/server/credential diagnostics }","preventionTips":["Ensure the user has a valid use license before opening protected XPS.","Verify RMS server reachability and client activation.","Surface InnerException details for support.","Handle expired credentials by re-authenticating the user."],"tags":["wpf","xps","rights-management","decryption"],"backgroundTag":"upstream-api-error","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}