{"record":{"id":"fa69a92e2f61b3ca","repo":"dotnet/wpf","slug":"0-name-is-already-in-use","errorCode":null,"errorMessage":"'{0}' name is already in use.","messagePattern":"'(.+?)' name is already in use\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StorageInfo.cs","lineNumber":169,"sourceCode":"\n        BuildStorageInfoRelativeToStorage( parent,  fileName );\n    }\n\n    /// <summary>\n    /// Respond to a request from a child StorageInfo object to give\n    /// it a StorageInfoCore object for the given name.\n    /// </summary>\n    private StorageInfoCore CoreForChildStorage( string storageNname )\n    {\n        CheckDisposedStatus();\n        \n        object childElement = core.elementInfoCores[ storageNname ];\n\n        if( null != childElement &&\n            null == childElement as StorageInfoCore )\n        {\n            // Name is already in use, but not as a StorageInfo\n            throw new InvalidOperationException(\n                SR.Format(SR.NameAlreadyInUse, storageNname ));\n        }\n        else if( null == childElement )\n        {\n            // No such element with the name exist - create one.\n            // \n            childElement = new StorageInfoCore( storageNname);\n            core.elementInfoCores[ storageNname ] = childElement;\n        }\n\n        Debug.Assert( null != childElement as StorageInfoCore,\n            \"We should have already checked to make sure childElement is either StorageInfoCore, created as one, or thrown an exception if neither is possible\");\n\n        return childElement as StorageInfoCore;\n    }\n\n    internal StreamInfoCore CoreForChildStream( string streamName )\n    {","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StorageInfo.cs#L151-L187","documentation":"StorageInfo.CoreForChildStorage refuses to create a child storage whose name is already used by a non-storage element (i.e. a stream) in the same parent. The compound file namespace requires storages and streams to occupy distinct names, so it throws InvalidOperationException with the formatted 'name is already in use' message.","triggerScenarios":"Calling CreateStorage (via BuildStorageInfoRelativeToStorage/CoreForChildStorage) with a name that already identifies a StreamInfo under the same parent storage.","commonSituations":"Building package structures programmatically where a stream named e.g. 'Data' exists and code then tries to create a storage with the same name; migrating documents between containers with colliding names.","solutions":["Check storage.GetStorageInfo(name) / existence of a stream with that name before creating the child storage","Choose a different, unique name for the new storage","Delete or rename the existing stream that occupies the name before creating the storage"],"exampleFix":"// before\nstorage.CreateStorage(\"Data\"); // 'Data' is an existing stream\n// after\nif (storage.GetStreamInfo(\"Data\") == null)\n    storage.CreateStorage(\"Data\");\nelse\n    storage.CreateStorage(\"DataStorage\");","handlingStrategy":"try-catch","validationCode":"bool nameFree = storage.GetStreamInfo(name) == null;\nif (nameFree) storage.CreateStorage(name);","typeGuard":"static bool IsFreeStorageName(StorageInfo s, string name) => s.GetStorageInfo(name) == null && s.GetStreamInfo(name) == null;","tryCatchPattern":"try { storage.CreateStorage(name); }\ncatch (InvalidOperationException) { storage.CreateStorage(name + \"_storage\"); }","preventionTips":["Remember storages and streams share one case-insensitive namespace","Generate child names from a schema that guarantees uniqueness","Enumerate existing children before bulk-creating structure"],"tags":["name-conflict","invalid-operation","compound-file","storage"],"backgroundTag":"address-already-in-use","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"}