dotnet/wpf · error · ArgumentException

CompoundFileReference: malformed path encountered.

Error message

CompoundFileReference: malformed path encountered.

What it means

ConvertBackSlashPathToStringArrayPath throws this ArgumentException when the backslash path starts or ends with whitespace (or otherwise cannot be represented as a compound-file path element array). The path string is malformed for the compound-file path format.

Solutions

  1. Pass a well-formed backslash-delimited path (no leading/trailing whitespace, valid characters) to ConvertBackSlashPathToStringArrayPath
  2. Normalize or repair the malformed path before conversion
  3. Catch ArgumentException and treat the path as invalid for the compound file operation
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs:301 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


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

Appendix: source

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

        ///     Mirror counterpart of ConvertStringArrayPathToBackSlashPath
        /// </remarks>

        // In theory, parsing strings should be done with regular expressions.
        // In practice, the RegEx class is too heavyweight for this application.

        // IMPORTANT: When updating this, make sure the counterpart is similarly
        //  updated.
        internal static string[] ConvertBackSlashPathToStringArrayPath(string backSlashPath)
        {
            // A null string will get a null array
            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;
        }

View on GitHub (pinned to 81131a70a4)