{"record":{"id":"3e554eb327dffcd9","repo":"dotnet/wpf","slug":"sr-rightsmanagementexceptionnorightsforoperation","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/Application/RightsManagementSuppressedStream.cs","lineNumber":162,"sourceCode":"\n        base.Write(buffer, offset, count);\n    }\n\n    #endregion Stream Overrides\n\n    #region Private Methods\n    //--------------------------------------------------------------------------\n    // Private Methods\n    //--------------------------------------------------------------------------\n\n    /// <summary>\n    /// Throws an appropriate exception if writing to the stream is not allowed.\n    /// </summary>\n    private void ThrowIfReadOnly()\n    {\n        if (!AllowWrite)\n        {\n            throw new InvalidOperationException(\n                SR.RightsManagementExceptionNoRightsForOperation);\n        }\n    }\n\n    #endregion Private Methods\n\n    #region Private Properties\n    //--------------------------------------------------------------------------\n    // Private Properties\n    //--------------------------------------------------------------------------\n    \n    /// <summary>\n    /// Returns whether or not the current RM permission set allows writing to\n    /// the stream.\n    /// </summary>\n    private bool AllowWrite\n    {\n        get","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/RightsManagementSuppressedStream.cs#L144-L180","documentation":"RightsManagementSuppressedStream.ThrowIfReadOnly guards write operations on a stream whose rights-management policy does not grant write rights. If AllowWrite is false, SetLength and Write throw InvalidOperationException(SR.RightsManagementExceptionNoRightsForOperation), reflecting the RM grant denial.","triggerScenarios":"Calling Write or SetLength on a RightsManagementSuppressedStream created from an RM environment/policy that lacks the Edit/Write right.","commonSituations":"User has view-only rights on a protected document; application attempts in-place save or annotation on a suppressed stream.","solutions":["Check the RM use-license rights (does it grant Edit/Write?) before attempting writes","Check the AllowWrite property before writing","Request elevated rights from the RM server (acquire a use license with the needed right)","Catch InvalidOperationException and degrade to read-only mode"],"exampleFix":"// before\nsuppressedStream.Write(buffer, 0, buffer.Length);\n// after\nif (suppressedStream.AllowWrite)\n    suppressedStream.Write(buffer, 0, buffer.Length);\nelse\n    /* open a copy with granted rights or notify the user */;","handlingStrategy":"validation","validationCode":"if (!stream.AllowWrite) { /* switch to read-only mode or acquire rights */ }","typeGuard":"bool CanWrite(SuppressedStream s) => s.AllowWrite;","tryCatchPattern":"try { stream.Write(buf, 0, buf.Length); } catch (InvalidOperationException ex) { /* degrade to read-only */ }","preventionTips":["Check AllowWrite before any Write/SetLength","Verify the use license grants write/edit rights at open time","Request needed rights from the RM server before editing"],"tags":["wpf","rights-management","drm","read-only-stream"],"backgroundTag":"permission-denied","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"}