{"record":{"id":"f10c45665b9d7004","repo":"dotnet/wpf","slug":"sr-containercannotopen","errorCode":null,"errorMessage":"SR.ContainerCanNotOpen","messagePattern":"SR\\.ContainerCanNotOpen","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StorageRoot.cs","lineNumber":361,"sourceCode":"                out newRootStorage );\n        }\n\n        switch( returnValue )\n        {\n            case SafeNativeCompoundFileConstants.S_OK:\n                return StorageRoot.CreateOnIStorage( \n                    newRootStorage );\n            case SafeNativeCompoundFileConstants.STG_E_FILENOTFOUND:\n                throw new FileNotFoundException( \n                    SR.ContainerNotFound);\n            case SafeNativeCompoundFileConstants.STG_E_INVALIDFLAG:\n                throw new ArgumentException( \n                    SR.StorageFlagsUnsupported,\n                    new COMException(\n                        SR.CFAPIFailure, \n                        returnValue));\n            default:\n                throw new IOException(\n                    SR.ContainerCanNotOpen,\n                    new COMException(\n                        SR.CFAPIFailure, \n                        returnValue));\n        }\n    }\n\n    /// <summary>\n    /// Clean up this container storage instance\n    /// </summary>\n    internal void Close()\n    {\n        if( null == rootIStorage )\n            return; // Extraneous calls to Close() are ignored\n\n        // Tell data space manager to flush all information as necessary\n        dataSpaceManager?.Dispose();\n        dataSpaceManager = null;","sourceCodeStart":343,"sourceCodeEnd":379,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StorageRoot.cs#L343-L379","documentation":"The native StgOpenStorageEx/StgCreateStorageEx call failed with an HRESULT not specifically mapped, so StorageRoot.Open throws IOException with ContainerCanNotOpen, wrapping a COMException(CFAPIFailure, hr). The container exists but could not be opened or created.","triggerScenarios":"Any unmapped native failure during StorageRoot.Open: corrupted compound file, access denied, file locked with incompatible share, not a valid compound file (e.g. a plain ZIP renamed to .docx in some paths), disk errors.","commonSituations":"Opening a damaged/truncated package; opening a file that is not actually an OLE compound file; insufficient permissions; file held by another process with exclusive access.","solutions":["Inspect the inner COMException HResult (e.g. STG_E_FILEALREADYEXISTS, STG_E_NOTFILEBASEDSTORAGE, ACCESS_DENIED) and fix accordingly.","Verify the file is a valid compound-file/OPC container and not corrupted; restore from backup.","Ensure the file is not locked by another process and the user has the required permissions.","Delete a zero-byte/corrupt file and recreate the package.","Run as a user with sufficient rights or copy the file to a writable location."],"exampleFix":"// before\nvar pkg = Package.Open(corruptedPath, FileMode.Open, FileAccess.ReadWrite);\n// after\ntry\n{\n    var pkg = Package.Open(path, FileMode.Open, FileAccess.ReadWrite);\n}\ncatch (IOException ex) when (ex.InnerException is COMException ce)\n{\n    // log ce.HResult, restore from backup or recreate the package\n}","handlingStrategy":"try-catch","validationCode":"if (!File.Exists(path) || new FileInfo(path).Length == 0)\n    throw new IOException(\"Container missing or empty\");","typeGuard":null,"tryCatchPattern":"try { pkg = Package.Open(path, FileMode.Open, FileAccess.Read); }\ncatch (IOException ex) when (ex.InnerException is COMException ce)\n{\n    var hr = ce.HResult; // log and recover: restore backup, fix permissions, or recreate\n}","preventionTips":["Validate the container is a real compound file before opening.","Check file permissions and locks (retry after closing other handles).","Keep backups of generated packages to recover from corruption."],"tags":["io","compound-file","corruption"],"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"}