dotnet/wpf · error · ArgumentException
' ' cannot start with the reserved character range…
Error message
'{0}' cannot start with the reserved character range 0x01-0x1F. What it means
CheckStringAgainstReservedName rejects names whose first character is in 0x01-0x1F, a range reserved for OLE compound files. If IsReservedName returns true, it throws ArgumentException (SR.StringCanNotBeReservedName). These control characters cannot be used as the first character of a compound-file storage or stream name.
Solutions
- Strip or reject control characters at the start of the name before calling the API
- Sanitize names (e.g. regex removal of [\x01-\x1F]) in an input-validation layer
- Catch ArgumentException and log/rename the offending name
Example fix
// before CreateStream(userInput); // after userInput = Regex.Replace(userInput, "^[\x01-\x1F]+", ""); CreateStream(userInput);
Defensive patterns
Strategy: validation
Validate before calling
if (name.Length > 0 && name[0] <= '\x1F') throw new ArgumentException("Name starts with reserved control character"); Type guard
static bool IsNameAllowed(string s) => string.IsNullOrEmpty(s) || s[0] > '\x1F';
Try / catch
try { CreateStream(name); } catch (ArgumentException ex) when (ex.Message.Contains("reserved")) { name = SanitizeName(name); CreateStream(name); } Prevention
- Sanitize user-supplied names by stripping control characters
- Reject binary/legacy data names before use
- Add a name whitelist/regex at the input layer
When it happens
Trigger: Calling a compound-file storage/stream creation API with a name string whose first character has code point 0x01-0x1F (control characters).
Common situations: Names built from unvalidated user or binary data where control characters slip into the first position, or legacy data containing old control-character prefixes.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- ' ' cannot contain the path delimiter: ' '.
- ' ' 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/1c73d154ad45f700.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs:423
{
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
/// reserved for use be OLE. These are names that start with a character in the
/// range 0x01 to 0x1F. (1-31)
/// This is a compound file restriction
/// </summary>
internal static bool IsReservedName(string nameString)
{
CheckStringAgainstNullAndEmpty(nameString, "nameString");
return (nameString[0] >= '\x0001'
&&
nameString[0] <= '\x001F');
}
View on GitHub (pinned to 81131a70a4)