{"record":{"id":"a8029f1a10cb4fa7","repo":"dotnet/wpf","slug":"parameter-cannot-be-a-zero-length-string","errorCode":null,"errorMessage":"Parameter cannot be a zero-length string.","messagePattern":"Parameter cannot be a zero-length string\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs","lineNumber":410,"sourceCode":"        /// <remarks>\n        ///\n        ///     CheckStringAgainstNullAndEmpty( fooName, \"The name parameter \");\n        ///\n        ///     may get:\n        ///\n        ///         ArgumentNullException \"The name parameter cannot be a null string\"\n        ///     or\n        ///         ArgumentException \"The name parameter cannot be an empty string\"\n        ///\n        ///</remarks>\n        internal static void CheckStringAgainstNullAndEmpty(string testString,\n            string testStringIdentifier)\n        {\n            if (testString == null)\n                throw new ArgumentNullException(testStringIdentifier);\n\n            if (testString.Length == 0)\n                throw new ArgumentException(SR.StringEmpty, testStringIdentifier);\n        }\n\n        /// <summary>\n        /// Checks if the given string fits within the range of reserved\n        /// names and throws an ArgumentException if it does.\n        /// The 0x01 through 0x1F characters, serving as the first character of the stream/storage name, \n        /// are reserved for use by OLE. This is a compound file restriction. \n        /// </summary>\n        internal static void CheckStringAgainstReservedName(string nameString,\n            string nameStringIdentifier)\n        {\n            if (IsReservedName(nameString))\n                throw new ArgumentException(\n                    SR.Format(SR.StringCanNotBeReservedName, nameStringIdentifier));\n        }\n\n        /// <summary>\n        /// A certain subset of compound file storage and stream names are ","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs#L392-L428","documentation":"ContainerUtilities.CheckStringAgainstNullAndEmpty validates compound-file name strings before use. If the string is non-null but zero-length, it throws ArgumentException with SR.StringEmpty. Compound file storage/stream names must be at least one character long, so empty identifiers are rejected early.","triggerScenarios":"Calling a WPF packaging API (e.g. creating a compound-file storage or stream via a path/name converted through ConvertStringArrayPathToBackSlashPath or checked by IsReservedName) with an empty (\"\") name string.","commonSituations":"Splitting a package part path with a separator and receiving an empty segment (e.g. trailing slash or consecutive delimiters) before passing it to compound-file APIs.","solutions":["Ensure the name string passed to the packaging API is non-empty before calling","Trim/validate path segments and drop empty segments before passing them","Catch ArgumentException and surface a clearer message about the empty name"],"exampleFix":"// before\nCreateStorage(\"\");\n// after\nif (string.IsNullOrEmpty(name)) throw new InvalidOperationException(\"Storage name must be non-empty\");\nCreateStorage(name);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(name)) throw new ArgumentException(\"Name must be non-empty\", nameof(name));","typeGuard":"static bool IsValidName(string s) => !string.IsNullOrEmpty(s);","tryCatchPattern":"try { CreateStream(name); } catch (ArgumentException ex) when (ex.Message.Contains(\"zero-length\") || ex.ParamName == nameof(name)) { /* handle empty name */ }","preventionTips":["Validate path segments and drop empty ones before compound-file APIs","Use string.IsNullOrEmpty checks at API boundaries","Beware of Split results containing empty entries (trailing/duplicate separators)"],"tags":["wpf","packaging","argumentexception"],"backgroundTag":"empty-required-field","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"}