dotnet/wpf · error · ArgumentException

Parameter cannot be a zero-length string.

Error message

Parameter cannot be a zero-length string.

What it means

ContainerUtilities.CheckStringAgainstNullAndEmpty validates compound-file name strings before use. If the string is non-null but zero-length, it throws ArgumentException with SR.StringEmpty. Compound file storage/stream names must be at least one character long, so empty identifiers are rejected early.

Solutions

  1. Ensure the name string passed to the packaging API is non-empty before calling
  2. Trim/validate path segments and drop empty segments before passing them
  3. Catch ArgumentException and surface a clearer message about the empty name

Example fix

// before
CreateStorage("");
// after
if (string.IsNullOrEmpty(name)) throw new InvalidOperationException("Storage name must be non-empty");
CreateStorage(name);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(name)) throw new ArgumentException("Name must be non-empty", nameof(name));

Type guard

static bool IsValidName(string s) => !string.IsNullOrEmpty(s);

Try / catch

try { CreateStream(name); } catch (ArgumentException ex) when (ex.Message.Contains("zero-length") || ex.ParamName == nameof(name)) { /* handle empty name */ }

Prevention

When it happens

Trigger: Calling a WPF packaging API (e.g. creating a compound-file storage or stream via a path/name converted through ConvertStringArrayPathToBackSlashPath or checked by IsReservedName) with an empty ("") name string.

Common situations: Splitting a package part path with a separator and receiving an empty segment (e.g. trailing slash or consecutive delimiters) before passing it to compound-file APIs.

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/a8029f1a10cb4fa7. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs:410

        /// <remarks>
        ///
        ///     CheckStringAgainstNullAndEmpty( fooName, "The name parameter ");
        ///
        ///     may get:
        ///
        ///         ArgumentNullException "The name parameter cannot be a null string"
        ///     or
        ///         ArgumentException "The name parameter cannot be an empty string"
        ///
        ///</remarks>
        internal static void CheckStringAgainstNullAndEmpty(string testString,
            string testStringIdentifier)
        {
            if (testString == null)
                throw new ArgumentNullException(testStringIdentifier);

            if (testString.Length == 0)
                throw new ArgumentException(SR.StringEmpty, testStringIdentifier);
        }

        /// <summary>
        /// Checks if the given string fits within the range of reserved
        /// names and throws an ArgumentException if it does.
        /// The 0x01 through 0x1F characters, serving as the first character of the stream/storage name, 
        /// are reserved for use by OLE. This is a compound file restriction. 
        /// </summary>
        internal static void CheckStringAgainstReservedName(string nameString,
            string nameStringIdentifier)
        {
            if (IsReservedName(nameString))
                throw new ArgumentException(
                    SR.Format(SR.StringCanNotBeReservedName, nameStringIdentifier));
        }

        /// <summary>
        /// A certain subset of compound file storage and stream names are 

View on GitHub (pinned to 81131a70a4)