{"record":{"id":"35c30d620c61ae07","repo":"dotnet/wpf","slug":"cannot-perform-this-function-on-a-stream-that-does-not-exist","errorCode":null,"errorMessage":"Cannot perform this function on a stream that does not exist.","messagePattern":"Cannot perform this function on a stream that does not exist\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StreamInfo.cs","lineNumber":712,"sourceCode":"            return SafeNativeCompoundFileConstants.S_OK == parentStorage.SafeIStorage.OpenStream(\n                core.streamName,\n                0,\n                SafeNativeCompoundFileConstants.STGM_READ | SafeNativeCompoundFileConstants.STGM_SHARE_EXCLUSIVE,\n                0,\n                out core.safeIStream );\n        }\n\n        /// <summary>\n        /// Most of the time internal methods that want to do an internal check \n        /// to see if a stream exists is only interested in proceeding if it does.\n        /// If it doesn't, abort with an exception.  This implements the little\n        /// shortcut.\n        /// </summary>\n        private void VerifyExists()\n        {\n            if( !InternalExists() )\n            {\n                throw new IOException(\n                    SR.StreamNotExist);\n            }\n            return;\n        }\n\n        private Stream CFStreamOfClone( FileAccess access )\n        {\n            long dummy = 0;\n\n            IStream cloneStream = null;\n            core.safeIStream.Clone( out cloneStream );\n            cloneStream.Seek( 0, SafeNativeCompoundFileConstants.STREAM_SEEK_SET, out dummy );\n\n            Stream returnStream = \n                BuildStreamOnUnderlyingIStream( cloneStream, access, this );\n\n            core.exposedStream = returnStream;\n","sourceCodeStart":694,"sourceCodeEnd":730,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StreamInfo.cs#L694-L730","documentation":"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.","triggerScenarios":"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).","commonSituations":"Deleting a package part twice; referring to a stream by a misspelled name; using a StreamInfo obtained before the underlying storage was reloaded.","solutions":["Check the Exists property before performing operations requiring the stream","Create the stream first if it is expected to exist lazily","Verify the stream name spelling and that the parent storage is the intended one"],"exampleFix":"// before\nstreamInfo.Delete(); // throws if not present\n// after\nif (streamInfo.Exists) streamInfo.Delete();","handlingStrategy":"validation","validationCode":"if (!streamInfo.Exists) throw new InvalidOperationException($\"Stream '{streamInfo.Name}' does not exist.\");","typeGuard":null,"tryCatchPattern":"try { streamInfo.Delete(); }\ncatch (IOException ex) when (ex.Message.Contains(\"does not exist\")) { /* already gone; treat as no-op */ }","preventionTips":["Guard delete/read operations with the Exists property","Track which streams you have created/deleted to avoid double-delete","Re-fetch StreamInfo after storage reloads"],"tags":["io","resource-not-found","packaging"],"backgroundTag":"resource-not-found","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}