dotnet/wpf · error · InvalidOperationException
' ' name is already in use.
Error message
'{0}' name is already in use. What it means
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.
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
Example fix
// before
storage.CreateStorage("Data"); // 'Data' is an existing stream
// after
if (storage.GetStreamInfo("Data") == null)
storage.CreateStorage("Data");
else
storage.CreateStorage("DataStorage"); Defensive patterns
Strategy: try-catch
Validate before calling
bool nameFree = storage.GetStreamInfo(name) == null; if (nameFree) storage.CreateStorage(name);
Type guard
static bool IsFreeStorageName(StorageInfo s, string name) => s.GetStorageInfo(name) == null && s.GetStreamInfo(name) == null;
Try / catch
try { storage.CreateStorage(name); }
catch (InvalidOperationException) { storage.CreateStorage(name + "_storage"); } Prevention
- 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
When it happens
Trigger: Calling CreateStorage (via BuildStorageInfoRelativeToStorage/CoreForChildStorage) with a name that already identifies a StreamInfo under the same parent storage.
Common situations: 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.
Related errors
- SR.CanNotDeleteRoot
- SR.CanNotDeleteNonEmptyStorage
- SR.StorageAlreadyExist
- SR.StorageNotExist
- SR.UnableToCreateStorage
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/fa69a92e2f61b3ca.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StorageInfo.cs:169
BuildStorageInfoRelativeToStorage( parent, fileName );
}
/// <summary>
/// Respond to a request from a child StorageInfo object to give
/// it a StorageInfoCore object for the given name.
/// </summary>
private StorageInfoCore CoreForChildStorage( string storageNname )
{
CheckDisposedStatus();
object childElement = core.elementInfoCores[ storageNname ];
if( null != childElement &&
null == childElement as StorageInfoCore )
{
// Name is already in use, but not as a StorageInfo
throw new InvalidOperationException(
SR.Format(SR.NameAlreadyInUse, storageNname ));
}
else if( null == childElement )
{
// No such element with the name exist - create one.
//
childElement = new StorageInfoCore( storageNname);
core.elementInfoCores[ storageNname ] = childElement;
}
Debug.Assert( null != childElement as StorageInfoCore,
"We should have already checked to make sure childElement is either StorageInfoCore, created as one, or thrown an exception if neither is possible");
return childElement as StorageInfoCore;
}
internal StreamInfoCore CoreForChildStream( string streamName )
{View on GitHub (pinned to 81131a70a4)