dotnet/wpf · error · IOException

SR.UnableToCreateStorage

Error message

SR.UnableToCreateStorage

What it means

Thrown by StorageInfo.CreateStorage when, after attempting to materialize the new sub-storage through the underlying IStorage, the storage still does not exist internally. It signals that IStorage.CreateStorage did not actually produce the requested element, i.e. the compound file layer failed silently or the name was rejected.

Solutions

  1. Use a valid compound-file element name (no invalid chars like '/', '\\', ':')
  2. Open the underlying file with FileAccess.ReadWrite and appropriate sharing so creation can succeed
  3. Check the file is not corrupted; re-create the compound file if IStorage behaves unexpectedly
  4. Catch IOException from CreateSubStorage and inspect the inner COMException HRESULT for the native error code
Defensive patterns

Strategy: try-catch

Validate before calling

if (!IsValidCompoundFileName(name)) throw new ArgumentException("Invalid compound file storage name", nameof(name));
if (root.OpenAccess == FileAccess.Read) throw new InvalidOperationException("Cannot create storage in read-only root");

Try / catch

try { var ss = storage.CreateSubStorage(name); }
catch (IOException ex) { /* inspect inner COMException HRESULT */ }

Prevention

When it happens

Trigger: Calling CreateStorage/CreateSubStorage on a storage where the native IStorage.CreateStorage call fails to produce the element (e.g. invalid name characters, corrupted file, read-only underlying file).

Common situations: Creating storages with names containing illegal compound-file characters; writing into a file opened from a read-only medium while the failure surfaces through this consistency check; corrupted OLE files.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StorageInfo.cs:631

                // If we don't exist, then ask parent to create us.
                parentStorage.CreateStorage( core.storageName );
            }
            //else if we already exist, we're done here.
        }
    }

    private StorageInfo CreateStorage(string name)
    {
        // Create new StorageInfo
        StorageInfo newSubStorage = new StorageInfo( this, name );
    
        // Make it real
        if( !newSubStorage.InternalExists(name) )
        {
            /* TBD
            if( !CU.IsValidCompoundFileName(name))
            {
                throw new IOException(
                        SR.UnableToCreateStorage,
                        new COMException( 
                            SR.Format(SR.NamedAPIFailure, "IStorage.CreateStorage"), 
                            nativeCallErrorCode ));
                }
                */
            // It doesn't already exist, please create.
            StorageInfoCore newStorage = core.elementInfoCores[ name ] as StorageInfoCore;
            Invariant.Assert( null != newStorage);
    
            int nativeCallErrorCode = core.safeIStorage.CreateStorage(
                        name, 
                    (GetStat().grfMode & SafeNativeCompoundFileConstants.STGM_READWRITE_Bits)
                        | SafeNativeCompoundFileConstants.STGM_SHARE_EXCLUSIVE,
                    0,
                    0,
                out newStorage.safeIStorage );
            if( SafeNativeCompoundFileConstants.S_OK != nativeCallErrorCode )

View on GitHub (pinned to 81131a70a4)