dotnet/wpf · error · InvalidOperationException

SR.RightsManagementExceptionNoRightsForOperation

Error message

SR.RightsManagementExceptionNoRightsForOperation

What it means

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.

Solutions

  1. Check the RM use-license rights (does it grant Edit/Write?) before attempting writes
  2. Check the AllowWrite property before writing
  3. Request elevated rights from the RM server (acquire a use license with the needed right)
  4. Catch InvalidOperationException and degrade to read-only mode

Example fix

// before
suppressedStream.Write(buffer, 0, buffer.Length);
// after
if (suppressedStream.AllowWrite)
    suppressedStream.Write(buffer, 0, buffer.Length);
else
    /* open a copy with granted rights or notify the user */;
Defensive patterns

Strategy: validation

Validate before calling

if (!stream.AllowWrite) { /* switch to read-only mode or acquire rights */ }

Type guard

bool CanWrite(SuppressedStream s) => s.AllowWrite;

Try / catch

try { stream.Write(buf, 0, buf.Length); } catch (InvalidOperationException ex) { /* degrade to read-only */ }

Prevention

When it happens

Trigger: Calling Write or SetLength on a RightsManagementSuppressedStream created from an RM environment/policy that lacks the Edit/Write right.

Common situations: User has view-only rights on a protected document; application attempts in-place save or annotation on a suppressed stream.

Understand the failure class

Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/RightsManagementSuppressedStream.cs:162

        base.Write(buffer, offset, count);
    }

    #endregion Stream Overrides

    #region Private Methods
    //--------------------------------------------------------------------------
    // Private Methods
    //--------------------------------------------------------------------------

    /// <summary>
    /// Throws an appropriate exception if writing to the stream is not allowed.
    /// </summary>
    private void ThrowIfReadOnly()
    {
        if (!AllowWrite)
        {
            throw new InvalidOperationException(
                SR.RightsManagementExceptionNoRightsForOperation);
        }
    }

    #endregion Private Methods

    #region Private Properties
    //--------------------------------------------------------------------------
    // Private Properties
    //--------------------------------------------------------------------------
    
    /// <summary>
    /// Returns whether or not the current RM permission set allows writing to
    /// the stream.
    /// </summary>
    private bool AllowWrite
    {
        get

View on GitHub (pinned to 81131a70a4)