dotnet/wpf · error · ArgumentException

SR.DelimiterLeading

Error message

SR.DelimiterLeading

What it means

CompoundFileStorageReference.SetFullName rejects a fullName that begins with the path separator ('/'). Container-relative names in the compound-file model are always relative, so a leading slash would produce an absolute path the container cannot represent. It throws ArgumentException with SR.DelimiterLeading naming the offending parameter.

Solutions

  1. Trim leading '/' characters from the name before assigning it: fullName.TrimStart('/') using Ordinal semantics on the path separator.
  2. Normalize the path first with a helper (e.g. strip leading separators, then split on '/').
  3. If an absolute path is required, resolve it against the container root externally and pass the relative remainder.
  4. Validate user input to reject or normalize absolute paths before constructing the reference.

Example fix

// before
var storageRef = new CompoundFileStorageReference("/Data/Storage1");
// after
string name = "/Data/Storage1".TrimStart('/');
var storageRef = new CompoundFileStorageReference(name); // "Data/Storage1"
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(name) || name.StartsWith("/", StringComparison.Ordinal)) throw new ArgumentException("Name must be relative and non-empty.");

Type guard

bool IsValidStorageName(string name) => !string.IsNullOrEmpty(name) && !name.StartsWith("/", StringComparison.Ordinal);

Try / catch

try { new CompoundFileStorageReference(name); }
catch (ArgumentException ex) { /* normalize and retry */ }

Prevention

When it happens

Trigger: Constructing a CompoundFileStorageReference or calling its FullName setter with a string starting with '/', e.g. new CompoundFileStorageReference("/storage1").

Common situations: Joining paths with string concatenation that leaves a leading slash, porting code from absolute-path APIs (Uri, filesystem paths) to container-relative names, or reading user-supplied part names without normalization.

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


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/6de3ec646961d555. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/CompoundFileStorageReference.cs:118

        /// Assign the fullName
        /// </summary>
        /// <param name="fullName">name</param>
        /// <remarks>cache a duplicate copy of the storage name to save having to do this for 
        /// every call to get_Name</remarks>
        /// <exception cref="ArgumentException">if leading or trailing path delimiter</exception>
        private void SetFullName(string fullName)
        {
            if (fullName == null || fullName.Length == 0)
            {
                _fullName = String.Empty;
            }
            else
            {
                // 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;

                // ensure that the string is a legal whack-path
                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

View on GitHub (pinned to 81131a70a4)