OrchardCMS/OrchardCore · error · FileStoreException

Cannot resolve physical path with the path

Error message

Cannot resolve physical path with the path '{path}'.

What it means

Generic catch-all in FileSystemStore.GetPhysicalPath: any non-FileStoreException thrown while combining/canonicalizing the path (e.g. Path.Combine or Path.GetFullPath failing on invalid characters, NotSupportedException, security exceptions) is re-wrapped as FileStoreException 'Cannot resolve physical path'. InnerException retains the cause.

Solutions

  1. Read the InnerException to see which path API failed and why.
  2. Sanitize the path before use: remove/rename invalid characters per the target OS (use a whitelist like [A-Za-z0-9._-]).
  3. Check the stored path data for corruption and repair the records producing bad paths.
  4. Catch FileStoreException around IFileStore calls and return a user-facing 'invalid path' message instead of crashing.

Example fix

// before
var path = $"media/{contentItem.DisplayText}.pdf";
await fileStore.CreateFileFromStreamAsync(path, stream);
// after
var invalid = Path.GetInvalidFileNameChars();
var safeName = string.Join("", contentItem.DisplayText.Split(invalid));
var path = $"media/{safeName}.pdf";
await fileStore.CreateFileFromStreamAsync(path, stream);
Defensive patterns

Strategy: validation

Validate before calling

if (path.IndexOfAny(Path.GetInvalidPathChars()) >= 0 || string.IsNullOrWhiteSpace(path))
{
    throw new ArgumentException($"Path '{path}' contains invalid characters.");
}

Type guard

static bool IsValidStorePath(string path) =>
    !string.IsNullOrWhiteSpace(path)
    && path.IndexOfAny(Path.GetInvalidPathChars()) < 0
    && !path.Contains('\0');

Try / catch

try
{
    var info = await fileStore.GetFileInfoAsync(path);
}
catch (FileStoreException ex) when (ex.Message.StartsWith("Cannot resolve physical path"))
{
    logger.LogError(ex.InnerException, "Unresolvable store path '{Path}'", path);
    throw new ApplicationException("The file path is invalid for this filesystem.", ex);
}

Prevention

When it happens

Trigger: Calling any IFileStore operation with a path containing invalid filesystem characters (e.g. '<', '|', ':' in a segment on Windows), embedded NULs, or an empty/whitespace-only segment that breaks Path.GetFullPath.

Common situations: Filenames derived from user content (content item titles) containing reserved characters; paths built from media URLs with un-encoded special characters; Linux-hosted content with ':' in names later served on Windows; corrupted stored paths from an earlier bug.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/3e36dbe5981cb6fd. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore/OrchardCore.FileStorage.FileSystem/FileSystemStore.cs:444

            var physicalPath = string.IsNullOrEmpty(path) ? _fileSystemPath : Path.Combine(_fileSystemPath, path);

            // Verify that the resulting path is inside the root file system path.
            var pathIsAllowed = Path.GetFullPath(physicalPath).StartsWith(_fileSystemPath, StringComparison.OrdinalIgnoreCase);
            if (!pathIsAllowed)
            {
                throw new FileStoreException($"The path '{path}' resolves to a physical path outside the file system store root.");
            }

            return physicalPath;
        }
        catch (FileStoreException)
        {
            throw;
        }
        catch (Exception ex)
        {
            throw new FileStoreException($"Cannot resolve physical path with the path '{path}'.", ex);
        }
    }
}

View on GitHub (pinned to 4306c0717f)