{"record":{"id":"d924c946c1306247","repo":"dotnet/wpf","slug":"sr-rightsmanagementexceptionnorightsforoperation-d924c9","errorCode":null,"errorMessage":"SR.RightsManagementExceptionNoRightsForOperation","messagePattern":"SR\\.RightsManagementExceptionNoRightsForOperation","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/DocumentApplicationDocumentViewer.cs","lineNumber":291,"sourceCode":"                SetupUIControls();\n                SetupUITabIndices();\n                _isUISetup = true;\n            }\n        }\n\n        /// <summary>\n        /// Handler for the Print command.\n        /// </summary>\n        protected override void OnPrintCommand()\n        {\n            if ((RightsManagementPolicy & RightsManagementPolicy.AllowPrint) ==\n                RightsManagementPolicy.AllowPrint)\n            {\n                OnPrintCommandPageRangeOverride();\n            }\n            else\n            {\n                throw new InvalidOperationException(\n                    SR.RightsManagementExceptionNoRightsForOperation);\n            }\n        }\n\n        /// <summary>\n        /// Handler for the CancelPrint command.\n        /// </summary>\n        protected override void OnCancelPrintCommand()\n        {\n#if !DONOTREFPRINTINGASMMETA\n            _documentWriter?.CancelAsync();\n#endif // DONOTREFPRINTINGASMMETA\n        }\n\n        /// <summary>\n        /// Called when WritingCompleted event raised by a DocumentWriter (during printing).\n        /// </summary>\n        /// <param name=\"sender\">Sender of the event.</param>","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/DocumentApplicationDocumentViewer.cs#L273-L309","documentation":"DocumentApplicationDocumentViewer.OnPrintCommand checks the RightsManagementPolicy before printing; if the AllowPrint policy bit is not granted for the rights-managed document it throws InvalidOperationException(SR.RightsManagementExceptionNoRightsForOperation). The user's rights grant simply does not include printing.","triggerScenarios":"Invoking the Print command (ApplicationCommands.Print) on a rights-managed XPS document whose granted UseRights mask lacks RightsManagementPolicy.AllowPrint.","commonSituations":"User opens a protected document licensed only for view/copy; pressing Ctrl+P or a print toolbar button in the XPS Document Application.","solutions":["Check the effective rights (RightsManagementPolicy.AllowPrint) before enabling the Print command; disable the UI instead of relying on the throw.","Request a new end-user license with print rights from the rights issuer if printing is legitimately needed.","Catch InvalidOperationException around the print invocation and show a 'printing not permitted' dialog."],"exampleFix":"// before\nprintButton.IsEnabled = true;\n// after\nprintButton.IsEnabled = (rmPolicy & RightsManagementPolicy.AllowPrint) != 0;","handlingStrategy":"validation","validationCode":"bool canPrint = (doc.RightsManagementPolicy & RightsManagementPolicy.AllowPrint) != 0;\nif (!canPrint) DisablePrintUi();","typeGuard":"bool HasRight(RightsManagementPolicy granted, RightsManagementPolicy needed) => (granted & needed) == needed;","tryCatchPattern":"try { docViewer.Print(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"NoRightsForOperation\"))\n{ ShowMessage(\"Printing is not permitted for this document.\"); }","preventionTips":["Gate print UI on granted rights.","Request print rights in the publish license when authoring.","Handle offline license refresh scenarios."],"tags":["wpf","xps","rights-management","permissions"],"backgroundTag":"permission-denied","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"}