{"record":{"id":"43dc8f6d5a418df6","repo":"dotnet/wpf","slug":"file-name-is-null-or-empty","errorCode":null,"errorMessage":"File name is null or empty.","messagePattern":"File name is null or empty\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/XpsFilter.cs","lineNumber":359,"sourceCode":"        /// <summary>\n        /// Opens the specified file with the specified mode..\n        /// This can return any of the STG_E_* error codes, along\n        /// with S_OK, E_OUTOFMEMORY, and E_FAIL.\n        /// </summary>\n        /// <param name=\"pszFileName\">\n        /// A zero-terminated string containing the absolute path of the file to open. \n        /// </param>\n        /// <param name=\"dwMode\">The mode in which to open pszFileName. </param>\n        void IPersistFile.Load(string pszFileName, int dwMode)\n        {\n            FileMode fileMode;\n            FileAccess fileAccess;\n            FileShare fileSharing;\n\n            // Check argument.\n            if (pszFileName == null || pszFileName == String.Empty)\n            {\n                throw new ArgumentException(SR.FileNameNullOrEmpty, nameof(pszFileName));\n            }\n\n            // Convert mode information in flag.\n            switch ((STGM_FLAGS)(dwMode & (int)STGM_FLAGS.MODE))\n            {\n                case STGM_FLAGS.CREATE:\n                    throw new ArgumentException(SR.FilterLoadInvalidModeFlag, nameof(dwMode));\n\n                default:\n                    fileMode = FileMode.Open;\n                    break;\n            }\n\n            // Convert access flag.\n            switch ((STGM_FLAGS)(dwMode & (int)STGM_FLAGS.ACCESS))\n            {\n                case STGM_FLAGS.READ:\n                case STGM_FLAGS.READWRITE:","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/XpsFilter.cs#L341-L377","documentation":"XpsFilter.Load (the IPersistFile implementation) validates the file name passed by the unmanaged filter host before opening anything. If pszFileName is null or the empty string, it throws ArgumentException with SR.FileNameNullOrEmpty because there is no file to open for filtering. This is an eager argument check so the failure happens before any mode or stream work.","triggerScenarios":"Calling IPersistFile.Load(null, mode) or Load(\"\", mode) on an XpsFilter instance, e.g. a Windows Search / IFilter host passing a missing path binding.","commonSituations":"Filter hosts or test harnesses that resolve the document path from an incomplete property bag or URL moniker, ending up with an empty path string.","solutions":["Ensure the file name passed to Load is a non-null, non-empty absolute path string","Validate the path in the caller before invoking Load (String.IsNullOrEmpty check)","If paths come from configuration or a moniker, fix the resolution so a real file path is supplied"],"exampleFix":"// before\nfilter.Load(null, (int)STGM_FLAGS.READ);\n// after\nstring path = GetDocumentPath();\nif (String.IsNullOrEmpty(path)) throw new InvalidOperationException(\"no document path\");\nfilter.Load(path, (int)STGM_FLAGS.READ);","handlingStrategy":"validation","validationCode":"if (String.IsNullOrEmpty(path)) throw new ArgumentException(\"A file path is required.\", nameof(path));","typeGuard":"static bool HasFileName(string s) => !String.IsNullOrEmpty(s);","tryCatchPattern":null,"preventionTips":["Validate paths with String.IsNullOrEmpty before any Load call","Resolve monikers/property bags to concrete paths before invoking the filter","Log the resolved path so empty bindings are caught early"],"tags":["argument","null","csharp","wpf"],"backgroundTag":"null-argument","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"}