{"record":{"id":"41e926246354d4c1","repo":"dotnet/wpf","slug":"sr-cannotonnonexiststorage","errorCode":null,"errorMessage":"SR.CanNotOnNonExistStorage","messagePattern":"SR\\.CanNotOnNonExistStorage","errorType":"exception","errorClass":"DirectoryNotFoundException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StorageInfo.cs","lineNumber":1114,"sourceCode":"                    SR.Format(SR.NamedAPIFailure, \"IStorage::OpenStorage\"), \n                    nativeCallErrorCode ));\n        }\n        // STG_E_NOTFOUND - return openSuccess as false \n\n        return openSuccess;\n    }\n\n    /// <summary>\n    /// Most of the time internal methods that want to do an internal check \n    /// to see if a storage 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 DirectoryNotFoundException(\n                SR.CanNotOnNonExistStorage);\n        }\n        return;\n    }\n\n    /// <summary>\n    /// Grabs the STATSTG representing us\n    /// </summary>\n    private System.Runtime.InteropServices.ComTypes.STATSTG GetStat()\n    {\n        System.Runtime.InteropServices.ComTypes.STATSTG returnValue;\n\n        VerifyExists();\n\n        core.safeIStorage.Stat( out returnValue, 0 );\n\n        return returnValue;\n    }","sourceCodeStart":1096,"sourceCodeEnd":1132,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StorageInfo.cs#L1096-L1132","documentation":"StorageInfo.VerifyExists checks InternalExists and throws DirectoryNotFoundException with SR.CanNotOnNonExistStorage when the storage does not exist in the compound file. Most public StorageInfo members call VerifyExists first, so operating on a deleted or never-created sub-storage fails fast with a directory-not-found semantics.","triggerScenarios":"Holding a StorageInfo reference and calling Exists-sensitive members (CreateSubStorage, CreateStreamInfo, enumerators, Open) after the sub-storage was deleted via DeleteSubStorage, or constructing/accessing a name that was never created.","commonSituations":"Stale StorageInfo references cached across container edits; misspelled storage names; deleting a storage then trying to enumerate its children.","solutions":["Check the Exists property on the StorageInfo before calling its methods.","Re-fetch a fresh StorageInfo from the root after any delete/rename instead of reusing stale references.","Create the storage first (CreateSubStorage) if it is supposed to exist.","Catch DirectoryNotFoundException around storage operations to treat missing storages as empty."],"exampleFix":"// before\nvar child = root.GetStorageInfo(\"Part1\");\nchild.DeleteSubStorage(\"Inner\"); // DirectoryNotFoundException if Part1 deleted\n// after\nvar child = root.GetStorageInfo(\"Part1\");\nif (child.Exists)\n    child.DeleteSubStorage(\"Inner\");","handlingStrategy":"validation","validationCode":"if (storageInfo == null || !storageInfo.Exists)\n    return null; // or recreate: root.CreateSubStorage(name)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always check Exists before operating on a StorageInfo.","Discard and re-fetch StorageInfo references after any delete/rename.","Avoid caching child storages across container mutations."],"tags":["io","compound-file","not-found","stale-reference"],"backgroundTag":"directory-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"}