dotnet/wpf · error · IOException
SR.WriteFailure
Error message
SR.WriteFailure
What it means
CFStream.Write throws IOException with SR.WriteFailure when the underlying compound-file native IStream.Write reports a byte count different from the requested count. A partial write inside a compound file means the storage engine could not commit all bytes, so the stream surface treats it as a hard I/O failure rather than silently accepting a short write.
Solutions
- Check available disk space and free space / quota before writing
- Verify the compound file is not corrupt (try opening it with a repair tool) and the media is writable
- Close and reopen the file, then retry the save operation
- Copy content to a new file if the original container is damaged
- Catch IOException around writes and implement save-to-temp-then-replace logic
Example fix
// before
cfStream.Write(data, 0, data.Length);
// after
try {
cfStream.Write(data, 0, data.Length);
} catch (IOException ex) {
throw new IOException("Compound file write failed (disk full or corrupt container?): " + ex.Message, ex);
} Defensive patterns
Strategy: try-catch
Validate before calling
// before writing
long free = new DriveInfo(Path.GetPathRoot(path)).AvailableFreeSpace;
if (free < data.Length + margin) throw new IOException("Insufficient disk space."); Try / catch
try { cfStream.Write(buffer, 0, count); } catch (IOException ex) { /* check disk space / file corruption, retry to temp file */ } Prevention
- Check disk free space / quota before large writes
- Write to a temp file then atomically replace on save
- Handle partial-write IOException as unrecoverable container damage
- Avoid writing compound files directly on flaky network shares
When it happens
Trigger: Calling Write when the compound file is full, the disk is out of space, the file is locked/corrupted, or the native StgWrite fails partway and reports written != count.
Common situations: Disk-quota or free-space exhaustion while saving large documents; writes to a compound file on a flaky network share or removable media; corrupted OLE container files that fail mid-write.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- ArgumentOutOfRangeException(nameof(offset))
- can’t seek on baseStream
- File contains data in format version
- Image_CannotCreateTempFile
- No file exists at
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/d7a0784eb33ff0d3.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/CFStream.cs:268
PackagingUtilities.VerifyStreamWriteArgs(this, buffer, offset, count);
int written = 0; // CLR guys have deemed this uninteresting?
if ( 0 == offset ) // Zero offset is typical case
{
_safeIStream.Write( buffer, count, out written );
}
else // Non-zero offset
{
// Copy from indicated offset to zero-based temp buffer
byte[] localBuffer = new byte[count];
Array.Copy(buffer, offset, localBuffer, 0, count);
_safeIStream.Write( localBuffer, count, out written );
}
if( count != written )
throw new IOException(
SR.WriteFailure);
}
//------------------------------------------------------
//
// Internal Methods
//
//------------------------------------------------------
// Check whether this Stream object is still valid. If not, thrown an
// ObjectDisposedException.
internal void CheckDisposedStatus()
{
if( StreamDisposed )
throw new ObjectDisposedException(null, SR.StreamObjectDisposed);
}
// Check whether this Stream object is still valid.View on GitHub (pinned to 81131a70a4)