dotnet/wpf · error · ArgumentException

File name is null or empty.

Error message

File name is null or empty.

What it means

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.

Solutions

  1. Ensure the file name passed to Load is a non-null, non-empty absolute path string
  2. Validate the path in the caller before invoking Load (String.IsNullOrEmpty check)
  3. If paths come from configuration or a moniker, fix the resolution so a real file path is supplied

Example fix

// before
filter.Load(null, (int)STGM_FLAGS.READ);
// after
string path = GetDocumentPath();
if (String.IsNullOrEmpty(path)) throw new InvalidOperationException("no document path");
filter.Load(path, (int)STGM_FLAGS.READ);
Defensive patterns

Strategy: validation

Validate before calling

if (String.IsNullOrEmpty(path)) throw new ArgumentException("A file path is required.", nameof(path));

Type guard

static bool HasFileName(string s) => !String.IsNullOrEmpty(s);

Prevention

When it happens

Trigger: Calling IPersistFile.Load(null, mode) or Load("", mode) on an XpsFilter instance, e.g. a Windows Search / IFilter host passing a missing path binding.

Common situations: 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.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/XpsFilter.cs:359

        /// <summary>
        /// Opens the specified file with the specified mode..
        /// This can return any of the STG_E_* error codes, along
        /// with S_OK, E_OUTOFMEMORY, and E_FAIL.
        /// </summary>
        /// <param name="pszFileName">
        /// A zero-terminated string containing the absolute path of the file to open. 
        /// </param>
        /// <param name="dwMode">The mode in which to open pszFileName. </param>
        void IPersistFile.Load(string pszFileName, int dwMode)
        {
            FileMode fileMode;
            FileAccess fileAccess;
            FileShare fileSharing;

            // Check argument.
            if (pszFileName == null || pszFileName == String.Empty)
            {
                throw new ArgumentException(SR.FileNameNullOrEmpty, nameof(pszFileName));
            }

            // Convert mode information in flag.
            switch ((STGM_FLAGS)(dwMode & (int)STGM_FLAGS.MODE))
            {
                case STGM_FLAGS.CREATE:
                    throw new ArgumentException(SR.FilterLoadInvalidModeFlag, nameof(dwMode));

                default:
                    fileMode = FileMode.Open;
                    break;
            }

            // Convert access flag.
            switch ((STGM_FLAGS)(dwMode & (int)STGM_FLAGS.ACCESS))
            {
                case STGM_FLAGS.READ:
                case STGM_FLAGS.READWRITE:

View on GitHub (pinned to 81131a70a4)