{"record":{"id":"b9aeedfdc454d708","repo":"dotnet/wpf","slug":"sr-cannotopenstorage","errorCode":null,"errorMessage":"SR.CanNotOpenStorage","messagePattern":"SR\\.CanNotOpenStorage","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StorageInfo.cs","lineNumber":1093,"sourceCode":"        int nativeCallErrorCode = 0;\n\n        nativeCallErrorCode = core.safeIStorage.OpenStorage(\n                nameInternal,\n                null,\n                (GetStat().grfMode & SafeNativeCompoundFileConstants.STGM_READWRITE_Bits)\n                    | SafeNativeCompoundFileConstants.STGM_SHARE_EXCLUSIVE,\n                IntPtr.Zero,\n                0,\n                out childCore.safeIStorage );\n\n        if( SafeNativeCompoundFileConstants.S_OK == nativeCallErrorCode )\n        {\n            openSuccess = true;\n        }\n        else if( SafeNativeCompoundFileConstants.STG_E_FILENOTFOUND != nativeCallErrorCode )\n        {\n            // Error is not STG_E_FILENOTFOUND, pass it on.\n            throw new IOException(\n                SR.CanNotOpenStorage, \n                new COMException( \n                    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    {","sourceCodeStart":1075,"sourceCodeEnd":1111,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StorageInfo.cs#L1075-L1111","documentation":"StorageInfo.CanOpenStorage calls IStorage::OpenStorage; when the returned native error code is anything other than STG_E_FILENOTFOUND the library throws IOException with SR.CanNotOpenStorage, wrapping a COMException named for IStorage::OpenStorage. STG_E_FILENOTFOUND is deliberately not thrown — instead openSuccess stays false so callers can check existence.","triggerScenarios":"Opening a named sub-storage whose IStorage::OpenStorage call fails with an error other than STG_E_FILENOTFOUND (access denied, name invalid, storage disposed) via GetStorageInfo/child storage access.","commonSituations":"Case/name mismatch resolving to invalid name errors, compound file corruption, accessing a storage on a root opened read-only when write-type access is requested.","solutions":["Check the exact child storage name (StgOpenStorage names are exact, not case-insensitive in all paths).","Reopen the StorageRoot with the correct FileAccess for the intended operation.","Verify the compound file is not corrupt by opening it in its owning application.","Catch IOException and inspect the inner COMException HResult for the specific STG_E_* code."],"exampleFix":"// before\nvar child = root.GetStorageInfo(\"Data\"); // may throw IOException\n// after\nStreamInfo si;\nif (root.TryGetStorageInfo(\"Data\", out var st) || root.StorageInfos.Any(s => s.Name == \"Data\"))\n    child = root.GetStorageInfo(\"Data\");","handlingStrategy":"validation","validationCode":"bool exists = root.GetStorageInfos().Any(s => s.Name == childName);\nif (!exists) return null; // avoid OpenStorage on a bogus name","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify child names exactly before opening.","Match FileAccess of the child operation to how the root was opened.","Catch IOException and inspect the inner COMException HResult."],"tags":["io","compound-file","com","open-storage"],"backgroundTag":"file-open-failed","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"}