{"record":{"id":"dcfa0d10389203f7","repo":"dotnet/wpf","slug":"cannot-have-leading-path-delimiter","errorCode":null,"errorMessage":"Cannot have leading path delimiter.","messagePattern":"Cannot have leading path delimiter\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/CompoundFileStreamReference.cs","lineNumber":133,"sourceCode":"        //\n        //   Private Methods\n        //\n        //------------------------------------------------------\n        /// <summary>\n        /// Initialize _fullName\n        /// </summary>\n        /// <remarks>this should only be called from constructors as references are immutable</remarks>\n        /// <param name=\"fullName\">string to parse</param>\n        /// <exception cref=\"ArgumentException\">if leading or trailing path delimiter</exception>\n        private void SetFullName(string fullName)\n        {\n            ContainerUtilities.CheckStringAgainstNullAndEmpty(fullName, \"fullName\");\n\n            // fail on leading path separator to match functionality across the board\n            // Although we need to do ToUpperInvariant before we do string comparison, in this case\n            //  it is not necessary since PathSeparatorAsString is a path symbol\n            if (fullName.StartsWith(ContainerUtilities.PathSeparatorAsString, StringComparison.Ordinal))\n                throw new ArgumentException(\n                    SR.DelimiterLeading, nameof(fullName));\n\n            _fullName = fullName;\n            string[] strings = ContainerUtilities.ConvertBackSlashPathToStringArrayPath(fullName);\n            if (strings.Length == 0)\n                throw new ArgumentException(\n                    SR.CompoundFilePathNullEmpty, nameof(fullName));\n        }\n\n        //------------------------------------------------------\n        //\n        //   Private members\n        //\n        //------------------------------------------------------\n        // this can never be null - use String.Empty\n        private String _fullName;  // whack-path\n    }\n}","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/CompoundFileStreamReference.cs#L115-L151","documentation":"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.","triggerScenarios":"new CompoundFileStreamReference(\"/file1\") or assigning FullName a string beginning with '/'.","commonSituations":"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.","solutions":["Strip leading '/' with fullName.TrimStart('/') before constructing the reference.","Normalize the path (remove leading separators) before passing it into the packaging API.","Convert absolute source paths to container-relative names explicitly (e.g. substring past the root).","Validate/normalize user- or config-supplied names at input boundaries."],"exampleFix":"// before\nvar streamRef = new CompoundFileStreamReference(absolutePath); // e.g. \"/Documents/File1\"\n// after\nstring relative = absolutePath.TrimStart('/');\nvar streamRef = new CompoundFileStreamReference(relative);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(name) || name.StartsWith(\"/\", StringComparison.Ordinal)) throw new ArgumentException(\"Stream name must be relative and non-empty.\");","typeGuard":"bool IsValidStreamName(string name) => !string.IsNullOrEmpty(name) && !name.StartsWith(\"/\", StringComparison.Ordinal);","tryCatchPattern":"try { new CompoundFileStreamReference(name); }\ncatch (ArgumentException ex) { name = name.TrimStart('/'); new CompoundFileStreamReference(name); }","preventionTips":["Strip leading separators from paths before assigning names","Convert absolute paths to container-relative names explicitly","Validate part names from users/config at boundaries"],"tags":["argument","path","validation","packaging"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}