dotnet/wpf · error · ArgumentException

Cannot have leading path delimiter.

Error message

Cannot have leading path delimiter.

What it means

CompoundFileStreamReference.SetFullName requires a relative container name; a fullName starting with the path separator ('/') is invalid because stream names are container-relative. It throws ArgumentException with SR.DelimiterLeading. Null/empty inputs are rejected earlier by CheckStringAgainstNullAndEmpty.

Solutions

  1. Strip leading '/' with fullName.TrimStart('/') before constructing the reference.
  2. Normalize the path (remove leading separators) before passing it into the packaging API.
  3. Convert absolute source paths to container-relative names explicitly (e.g. substring past the root).
  4. Validate/normalize user- or config-supplied names at input boundaries.

Example fix

// before
var streamRef = new CompoundFileStreamReference(absolutePath); // e.g. "/Documents/File1"
// after
string relative = absolutePath.TrimStart('/');
var streamRef = new CompoundFileStreamReference(relative);
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

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

Try / catch

try { new CompoundFileStreamReference(name); }
catch (ArgumentException ex) { name = name.TrimStart('/'); new CompoundFileStreamReference(name); }

Prevention

When it happens

Trigger: new CompoundFileStreamReference("/file1") or assigning FullName a string beginning with '/'.

Common situations: Building part names from absolute filesystem paths or URIs without stripping the root separator, concatenating a base path ending in '/' with a name, porting from APIs that accept absolute paths.

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/dcfa0d10389203f7. Report an issue: GitHub.

Appendix: source

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

        //
        //   Private Methods
        //
        //------------------------------------------------------
        /// <summary>
        /// Initialize _fullName
        /// </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)