dotnet/wpf · error · ArgumentException
The given data space label name is already in use.
Error message
The given data space label name is already in use.
What it means
DataSpaceManager.DefineDataSpace throws ArgumentException (SR.DataSpaceLabelInUse) when the newDataSpaceLabel already names a defined data space. Labels are unique per compound file; defining a duplicate is rejected.
Solutions
- Check DataSpaceIsDefined(label) before calling DefineDataSpace and skip/reuse if it exists.
- Choose a unique label (append a counter or timestamp) when creating multiple data spaces.
- Use a fresh compound file if the old label must be redefined with a different transform stack.
Example fix
// before
manager.DefineDataSpace(stack, "EncryptedData"); // throws on second run
// after
if (!manager.DataSpaceIsDefined("EncryptedData"))
manager.DefineDataSpace(stack, "EncryptedData"); Defensive patterns
Strategy: validation
Validate before calling
if (manager.DataSpaceIsDefined(label)) { /* skip define or pick a new label */ } Try / catch
try { manager.DefineDataSpace(stack, label); } catch (ArgumentException) { label = label + Guid.NewGuid().ToString("N"); manager.DefineDataSpace(stack, label); } Prevention
- Always check DataSpaceIsDefined before defining
- Make initialization idempotent for repeated runs
- Use unique labels per data space
When it happens
Trigger: Calling DefineDataSpace(stack, label) where DataSpaceIsDefined(label) is true — i.e. the label was defined earlier in the same compound file session.
Common situations: Re-running an initialization routine against an existing compound file, or retrying code after a partial failure where the first define already succeeded.
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- SR.TransformStackValid
- Can only countersign parts with Digital Signature…
- Duplicates not allowed - signature part already exists.
- Must specify an item to sign.
- Parameter cannot be a zero-length string.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/1754b5b1003c6c3a.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/DataSpaceManager.cs:589
/// <param name="newDataSpaceLabel">New data space label</param>
internal void DefineDataSpace( string[] transformStack, string newDataSpaceLabel )
{
CheckDisposedStatus();
// Data space must have at least one transform
if( null == transformStack ||
0 == transformStack.Length )
throw new ArgumentException(
SR.TransformStackValid);
// Given label must be a non-empty string
CU.CheckStringAgainstNullAndEmpty(newDataSpaceLabel, "newDataSpaceLabel");
// Given label must not be a reserved string
CU.CheckStringAgainstReservedName(newDataSpaceLabel, "newDataSpaceLabel");
// Given label must not already be in use
if( DataSpaceIsDefined( newDataSpaceLabel ) )
throw new ArgumentException(
SR.DataSpaceLabelInUse);
// Given transform array must include labels that have already been defined
foreach( string transformLabel in transformStack )
{
CU.CheckStringAgainstNullAndEmpty( transformLabel, "Transform label" );
if( !TransformLabelIsDefined( transformLabel ) )
throw new ArgumentException(
SR.TransformLabelUndefined);
}
// Passes all inspection, data space definition successful.
SetDataSpaceDefinition( newDataSpaceLabel, new DataSpaceDefinition(new ArrayList(transformStack), null));
_dirtyFlag = true;
return;
}View on GitHub (pinned to 81131a70a4)