dotnet/wpf · error · IOException

Cannot perform this function on a stream that does not…

Error message

Cannot perform this function on a stream that does not exist.

What it means

VerifyExists checks whether the named stream actually exists in the parent storage and throws IOException if it does not. Methods that require an existing stream (e.g. delete/read helpers) use it as a precondition check.

Solutions

  1. Check the Exists property before performing operations requiring the stream
  2. Create the stream first if it is expected to exist lazily
  3. Verify the stream name spelling and that the parent storage is the intended one

Example fix

// before
streamInfo.Delete(); // throws if not present
// after
if (streamInfo.Exists) streamInfo.Delete();
Defensive patterns

Strategy: validation

Validate before calling

if (!streamInfo.Exists) throw new InvalidOperationException($"Stream '{streamInfo.Name}' does not exist.");

Try / catch

try { streamInfo.Delete(); }
catch (IOException ex) when (ex.Message.Contains("does not exist")) { /* already gone; treat as no-op */ }

Prevention

When it happens

Trigger: Calling operations on a StreamInfo whose stream was never created or was already deleted (e.g. StreamInfo.Delete on a nonexistent stream, or after the parent storage was recreated).

Common situations: Deleting a package part twice; referring to a stream by a misspelled name; using a StreamInfo obtained before the underlying storage was reloaded.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StreamInfo.cs:712

            return SafeNativeCompoundFileConstants.S_OK == parentStorage.SafeIStorage.OpenStream(
                core.streamName,
                0,
                SafeNativeCompoundFileConstants.STGM_READ | SafeNativeCompoundFileConstants.STGM_SHARE_EXCLUSIVE,
                0,
                out core.safeIStream );
        }

        /// <summary>
        /// Most of the time internal methods that want to do an internal check 
        /// to see if a stream exists is only interested in proceeding if it does.
        /// If it doesn't, abort with an exception.  This implements the little
        /// shortcut.
        /// </summary>
        private void VerifyExists()
        {
            if( !InternalExists() )
            {
                throw new IOException(
                    SR.StreamNotExist);
            }
            return;
        }

        private Stream CFStreamOfClone( FileAccess access )
        {
            long dummy = 0;

            IStream cloneStream = null;
            core.safeIStream.Clone( out cloneStream );
            cloneStream.Seek( 0, SafeNativeCompoundFileConstants.STREAM_SEEK_SET, out dummy );

            Stream returnStream = 
                BuildStreamOnUnderlyingIStream( cloneStream, access, this );

            core.exposedStream = returnStream;

View on GitHub (pinned to 81131a70a4)