dotnet/wpf · error · ArgumentException

SR.DataSpaceLabelInvalidEmpty

Error message

SR.DataSpaceLabelInvalidEmpty

What it means

ArgumentException thrown by StreamInfo.Create when the dataSpace label argument is a non-null but zero-length string. The data space label names a transform/encryption data space to associate with the new stream; an empty string is not a meaningful label, so the library rejects it immediately. Pass null for 'no data space' or a valid non-empty label.

Solutions

  1. Pass null instead of "" when no data space label is needed.
  2. Normalize empty strings to null at the call site before invoking Create.
  3. If a label is intended, supply the correct non-empty data space name (e.g. "DRMTransform").

Example fix

// before
streamInfo.Create(content, FileAccess.Write, label ?? "");
// after
streamInfo.Create(content, FileAccess.Write,
    string.IsNullOrEmpty(label) ? null : label);
Defensive patterns

Strategy: validation

Validate before calling

if (dataSpace != null && dataSpace.Length == 0) throw new ArgumentException("dataSpace must be null or a non-empty label.");

Type guard

bool IsValidDataSpaceLabel(string dataSpace) => dataSpace == null || dataSpace.Length > 0;

Try / catch

try { streamInfo.Create(content, access, dataSpace); }
catch (ArgumentException) { streamInfo.Create(content, access, null); }

Prevention

When it happens

Trigger: Calling streamInfo.Create(content, access, "") or Create(..., dataSpace: string.Empty) — an empty-string label instead of null.

Common situations: Building the label from configuration or user input where an empty value wasn't normalized to null; string concatenation that yields "".

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

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

        /// <param name="dataSpace">Data space encoding</param>
        /// <returns>Stream object to manipulate data</returns>
        internal Stream Create( FileMode mode, FileAccess access, string dataSpace )
        {
            CheckDisposedStatus();
        
            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;
            }

View on GitHub (pinned to 81131a70a4)