dotnet/wpf · error · NotSupportedException
SR.WriteNotSupported
Error message
SR.WriteNotSupported
What it means
DeobfuscatingStream is a read-only stream that decrypts obfuscated XPS package content on read. Its Write override unconditionally throws NotSupportedException (SR.WriteNotSupported) after checking disposal — writes are simply not a supported operation on this stream.
Solutions
- Write to an underlying writable FileStream and wrap it for obfuscation instead
- Only read from DeobfuscatingStream; use CanWrite to branch before writing
- Check stream.CanWrite before calling write APIs
Example fix
// before dest = new DeobfuscatingStream(...); dest.Write(data, 0, data.Length); // after using var dest = File.Create(path); dest.Write(data, 0, data.Length);
Defensive patterns
Strategy: type-guard
Validate before calling
if (!stream.CanWrite) throw/log instead of writing;
Type guard
static bool IsWritable(Stream s) => s.CanWrite;
Try / catch
try { stream.Write(buf, 0, buf.Length); } catch (NotSupportedException) { /* write to underlying FileStream instead */ } Prevention
- Check Stream.CanWrite before any write API
- Never pass DeobfuscatingStream where a sink stream is expected
- Persist changes via the original file, not the deobfuscating view
When it happens
Trigger: Calling Write (or a wrapper that writes, e.g. StreamWriter/CopyTo into it) on a DeobfuscatingStream instance.
Common situations: Passing the deobfuscating stream to APIs that both read and write (e.g. Stream.CopyTo in the wrong direction), or trying to modify an obfuscated XPS file in place.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Stream does not support SetLength.
- SR.DocumentStreamMustBeFileSource
- SR.DocumentStreamMustBeTemporary
- SR.PackageControllerStreamCorruption
- SR.ReachSerialization_NotSupported
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/def39aea7bb62cb7.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/DeobfuscatingStream.cs:72
// Read in the raw data from the underlying stream
int bytesRead = _obfuscatedStream.Read(buffer, offset, count);
// Apply de-obfuscatation as necessary
Deobfuscate(buffer, offset, bytesRead, readPosition);
return bytesRead;
}
/// <summary>
/// Write
/// </summary>
/// <remarks>This is a read-only stream; throw now supported exception</remarks>
public override void Write(byte[] buffer, int offset, int count)
{
CheckDisposed();
throw new NotSupportedException(SR.WriteNotSupported);
}
/// <summary>
/// Seek
/// </summary>
/// <param name="offset">offset</param>
/// <param name="origin">origin</param>
public override long Seek(long offset, SeekOrigin origin)
{
CheckDisposed();
return _obfuscatedStream.Seek(offset, origin);
}
/// <summary>
/// SetLength
/// </summary>
/// <remarks>This is a read-only stream; throw now supported exception</remarks>View on GitHub (pinned to 81131a70a4)