dotnet/wpf · error · ArgumentException

SR.DataSpaceLabelUndefined

Error message

SR.DataSpaceLabelUndefined

What it means

ArgumentException thrown by StreamInfo.Create when the supplied dataSpace label is non-empty but is not defined in the compound file's DataSpaceManager (DataSpaceIsDefined returns false). The label must reference a data space previously defined/registered in the file's data space map (e.g. a transform such as the RM/encryption transform).

Solutions

  1. Verify the label with root.GetDataSpaceManager().DataSpaceIsDefined(label) before calling Create.
  2. Register/define the data space in the DataSpaceManager first, or obtain the correct label from the transform installation (e.g. the standard encrypted-transform label).
  3. Pass null if you don't actually need a data space on the stream.
  4. Check for typos/case differences against the defined data space names.

Example fix

// before
streamInfo.Create(content, FileAccess.Write, "EncryptedSpace"); // not defined
// after
var dsm = storageRoot.GetDataSpaceManager();
string label = "EncryptedSpace";
if (!dsm.DataSpaceIsDefined(label))
    throw new InvalidOperationException("Data space must be defined before use.");
streamInfo.Create(content, FileAccess.Write, label);
Defensive patterns

Strategy: validation

Validate before calling

var dsm = parentStorage.Root.GetDataSpaceManager();
if (dataSpace != null && !dsm.DataSpaceIsDefined(dataSpace)) throw new ArgumentException($"Data space '{dataSpace}' is not defined in this compound file.");

Try / catch

try { streamInfo.Create(content, access, dataSpace); }
catch (ArgumentException) { /* define/register the data space or pass null and retry */ }

Prevention

When it happens

Trigger: Calling streamInfo.Create(content, access, "MyTransform") where "MyTransform" was never added to the root's DataSpaceManager; typos in the label; applying a label to a file that was never set up with that transform.

Common situations: Hand-rolling rights-management/encryption on package streams; copying code that references a transform defined in a different file; renaming transforms without updating stream creation code.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StreamInfo.cs:449

        
            int grfMode = 0;
            IStream createdSafeIStream = null;
            DataSpaceManager dataSpaceManager = null;

            // Check to make sure root container is not read-only, and that
            //  we're not pointlessly trying to create a read-only stream.
            CreateTimeReadOnlyCheck( access );

            // Check to see if the data space label is valid
            if( null != dataSpace )
            {
                if( 0 == dataSpace.Length )
                    throw new ArgumentException(
                        SR.DataSpaceLabelInvalidEmpty);
            
                dataSpaceManager = parentStorage.Root.GetDataSpaceManager();
                if( !dataSpaceManager.DataSpaceIsDefined( dataSpace ) )
                    throw new ArgumentException(
                        SR.DataSpaceLabelUndefined);
            }

            openFileAccess = access;
            // becasue of the stream caching mechanism we must adjust FileAccess parameter. 
            // We want to open stream with the widest access posible, in case Package was open in ReadWrite 
            // we need to open stream in ReadWrite even if user explicitly asked us to do ReadOnly/WriteOnly. 
            // There is a possibility of a next request coming in as as ReadWrite request, and we would like to
            // take advanatage of the cached stream by wrapping with appropriate access limitations.
            if (parentStorage.Root.OpenAccess == FileAccess.ReadWrite)
            {
                access = FileAccess.ReadWrite;
            }

            // Generate the access flags from the access parameter
            SafeNativeCompoundFileMethods.UpdateModeFlagFromFileAccess( access, ref grfMode );
            
            // Only SHARE_EXCLUSIVE for now, FileShare issue TBD

View on GitHub (pinned to 81131a70a4)