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
- Ensure the name string passed to the packaging API is non-empty before calling
- Trim/validate path segments and drop empty segments before passing them
- 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
- Validate path segments and drop empty ones before compound-file APIs
- Use string.IsNullOrEmpty checks at API boundaries
- Beware of Split results containing empty entries (trailing/duplicate separators)
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
- Can only countersign parts with Digital Signature…
- Duplicates not allowed - signature part already exists.
- Must specify an item to sign.
- SR.TransformStackValid
- The given data space label name is already in use.
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)