dotnet/wpf · error · ArgumentException
Path string cannot include an empty element.
Error message
Path string cannot include an empty element.
What it means
ConvertBackSlashPathToStringArrayPath throws this ArgumentException when splitting the backslash path on separators yields an empty element — i.e. the path contains consecutive backslashes or a trailing separator. Empty path components are not valid in compound-file paths.
Solutions
- Remove empty path segments (consecutive backslashes) from the path before conversion
- Ensure paths like 'dir\sub\' are normalized to avoid empty elements
- Catch ArgumentException and surface a malformed-path error to the caller
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs:312 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/451bf4f74213c4b5.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs:312
if ((null == backSlashPath) || (0 == backSlashPath.Length))
return Array.Empty<string>();
// Reject leading/trailing whitespace
if (Char.IsWhiteSpace(backSlashPath[0]) ||
Char.IsWhiteSpace(backSlashPath[backSlashPath.Length - 1]))
{
throw new ArgumentException(SR.MalformedCompoundFilePath);
}
// Build the array
string[] splitArray =
backSlashPath.Split(PathSeparator);
// Look for empty strings in the array
foreach (string arrayElement in splitArray)
{
if (0 == arrayElement.Length)
throw new ArgumentException(
SR.PathHasEmptyElement, nameof(backSlashPath));
}
// No empty strings, this array should be fine.
return splitArray;
}
/// <summary>
/// Concatenates the names in an array of strings into a backslash-
/// delimited string.
///
/// string[] { "images", "button.jpg" } -> string "images\button.jpg"
///
/// </summary>
/// <param name="arrayPath">
/// String array of names
/// </param>
/// <returns>View on GitHub (pinned to 81131a70a4)