dotnet/wpf · error · ArgumentException
' ' cannot contain the path delimiter: ' '.
Error message
'{0}' cannot contain the path delimiter: '{1}'. What it means
CheckStringForEmbeddedPathSeparator rejects strings containing the compound-file path separator (backslash). Compound-file element names are single path segments; embedded separators would imply a path, which is not allowed within one name.
Solutions
- Pass only the final path segment, not a full path, as the name
- Split the path into segments yourself and create intermediate storages for each level
- Catch ArgumentException and detect the embedded delimiter to give a clearer message
Example fix
// before
CreateStream("folder\\file.bin");
// after
string name = Path.GetFileName("folder\\file.bin");
CreateStream(name); // create storages for intermediate segments separately Defensive patterns
Strategy: validation
Validate before calling
if (name.Contains('\\')) throw new ArgumentException("Name must be a single path segment, not a path"); Type guard
static bool IsSingleSegment(string s) => !string.IsNullOrEmpty(s) && !s.Contains('\\'); Try / catch
try { CreateStream(name); } catch (ArgumentException ex) when (ex.Message.Contains("delimiter")) { /* split path and create storages */ } Prevention
- Pass Path.GetFileName output, never full paths, as element names
- Create intermediate storages explicitly for each path level
- Document that compound-file element names are single segments
When it happens
Trigger: Calling ConvertStringArrayPathToBackSlashPath or related compound-file APIs with a name string containing '\'.
Common situations: Passing a full path (e.g. "folder\file") where only a single segment name is expected.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- ' ' cannot start with the reserved character range…
- ' ' ID is not a valid XSD ID.
- ' ' is not a valid value for ' '.
- Can only countersign parts with Digital Signature…
- Cannot countersign an unsigned package.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/e678e6ec91bb7525.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs:453
CheckStringAgainstNullAndEmpty(nameString, "nameString");
return (nameString[0] >= '\x0001'
&&
nameString[0] <= '\x001F');
}
/// <summary>
/// Checks for embedded delimiter in the string (as well as Null and Empty)
/// </summary>
/// <param name="testString">string to test</param>
/// <param name="testStringIdentifier">message for exception</param>
internal static void CheckStringForEmbeddedPathSeparator(string testString,
string testStringIdentifier)
{
CheckStringAgainstNullAndEmpty(testString, testStringIdentifier);
if (testString.Contains(PathSeparator))
throw new ArgumentException(
SR.Format(SR.NameCanNotHaveDelimiter,
testStringIdentifier,
PathSeparator), nameof(testString));
}
#endif
}
}
View on GitHub (pinned to 81131a70a4)