dotnet/wpf · error · ArgumentException
CompoundFile path must be non-empty.
Error message
CompoundFile path must be non-empty.
What it means
CompoundFileStreamReference.SetFullName rejects names that reduce to an empty path: after ConvertBackSlashPathToStringArrayPath yields zero segments, the stream cannot be identified. It throws ArgumentException with SR.CompoundFilePathNullEmpty. A stream name must contain at least one path segment.
Solutions
- Guard with String.IsNullOrEmpty and require at least one non-segment character before constructing.
- Validate that the split path yields >= 1 segment before calling the API.
- Fix upstream code to propagate real names or skip empty entries instead of passing them through.
- Add input validation at the config/UI boundary.
Example fix
// before
var streamRef = new CompoundFileStreamReference(name); // name may be ""
// after
if (string.IsNullOrWhiteSpace(name) || name.Split('/').All(string.IsNullOrEmpty))
throw new ArgumentException("Stream name must be a non-empty path.", nameof(name));
var streamRef = new CompoundFileStreamReference(name); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(name) || name.Split('/').All(string.IsNullOrEmpty)) throw new ArgumentException("Stream name must be a non-empty path."); Type guard
bool IsNonEmptyStreamPath(string name) => !string.IsNullOrEmpty(name) && ContainerUtilities.ConvertBackSlashPathToStringArrayPath(name).Length > 0;
Try / catch
try { new CompoundFileStreamReference(name); }
catch (ArgumentException) { throw new ArgumentException("Non-empty stream path required.", nameof(name)); } Prevention
- Reject null/empty/separator-only names before API calls
- Initialize name variables with valid defaults
- Validate config and form inputs for emptiness
When it happens
Trigger: new CompoundFileStreamReference("") or a name consisting only of separators that produces an empty string array.
Common situations: Uninitialized/default string variables, empty values from config files or user forms, upstream parsing failures yielding empty names.
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
- SR.CompoundFilePathNullEmpty
- Cannot have leading path delimiter.
- SR.DataSpaceLabelInvalidEmpty
- SR.DelimiterLeading
- Feature ID string cannot have zero length.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/2d78d02c7acb6a82.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/CompoundFileStreamReference.cs:139
/// </summary>
/// <remarks>this should only be called from constructors as references are immutable</remarks>
/// <param name="fullName">string to parse</param>
/// <exception cref="ArgumentException">if leading or trailing path delimiter</exception>
private void SetFullName(string fullName)
{
ContainerUtilities.CheckStringAgainstNullAndEmpty(fullName, "fullName");
// fail on leading path separator to match functionality across the board
// Although we need to do ToUpperInvariant before we do string comparison, in this case
// it is not necessary since PathSeparatorAsString is a path symbol
if (fullName.StartsWith(ContainerUtilities.PathSeparatorAsString, StringComparison.Ordinal))
throw new ArgumentException(
SR.DelimiterLeading, nameof(fullName));
_fullName = fullName;
string[] strings = ContainerUtilities.ConvertBackSlashPathToStringArrayPath(fullName);
if (strings.Length == 0)
throw new ArgumentException(
SR.CompoundFilePathNullEmpty, nameof(fullName));
}
//------------------------------------------------------
//
// Private members
//
//------------------------------------------------------
// this can never be null - use String.Empty
private String _fullName; // whack-path
}
}
View on GitHub (pinned to 81131a70a4)