dotnet/wpf · error · ArgumentException

SR.PackagingWriteNotSupported

Error message

SR.PackagingWriteNotSupported

What it means

TransactionalPackage.EnableEditMode accepts the workspace stream used to stage temporary edits. If the stream passes the null check but cannot be written (workspace.CanWrite is false), it throws ArgumentException(SR.PackagingWriteNotSupported, nameof(workspace)) because edit mode requires a writable workspace.

Solutions

  1. Pass a writable workspace stream (CanWrite == true), e.g. FileMode.Open with FileAccess.ReadWrite
  2. Create the workspace over a temp file: File.Create(Path.GetTempFileName())
  3. Verify workspace.CanWrite before calling EnableEditMode
  4. Catch ArgumentException and inform the user the document cannot be edited

Example fix

// before
package.EnableEditMode(File.OpenRead(docPath));
// after
using var workspace = File.Create(Path.GetTempFileName());
if (workspace.CanWrite)
    package.EnableEditMode(workspace);
Defensive patterns

Strategy: validation

Validate before calling

if (workspace == null || !workspace.CanWrite) { /* obtain a writable workspace first */ }

Type guard

bool IsValidWorkspace(Stream s) => s != null && s.CanWrite;

Try / catch

try { pkg.EnableEditMode(ws); } catch (ArgumentException ex) when (ex.ParamName == "workspace") { /* get a writable workspace */ }

Prevention

When it happens

Trigger: Calling EnableEditMode with a read-only stream (e.g., a stream opened with FileAccess.Read, a stream wrapped by a read-only StreamProxy, or a read-only network stream).

Common situations: Enabling edit mode on a document whose backing store is read-only media; passing a stream opened from a read-only file.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/TransactionalPackage.cs:82

        _originalPackage = originalPackage;
        _tempPackage = null;
    }
    #endregion Constructors

    #region Internal Methods
    //-------------------------------------------------------------------------
    // Internal Methods
    //-------------------------------------------------------------------------

    /// <exception cref="System.ArgumentNullException" />
    internal void EnableEditMode(Stream workspace)
    {
        ArgumentNullException.ThrowIfNull(workspace);

        if (!workspace.CanWrite)
        {
            throw new ArgumentException(
                SR.PackagingWriteNotSupported,
                nameof(workspace));
        }

        Package temporaryPackage = Package.Open(
            workspace, FileMode.Create, FileAccess.ReadWrite);

        _tempPackage = temporaryPackage;
    }

    /// <exception cref="System.ArgumentNullException" />
    /// <exception cref="System.ArgumentException" />
    internal virtual void MergeChanges(Stream target)
    {
        ArgumentNullException.ThrowIfNull(target);

        if (!target.CanWrite)
        {

View on GitHub (pinned to 81131a70a4)