OrchardCMS/OrchardCore · error · FileStoreException

Cannot get file stream of the file

Error message

Cannot get file stream of the file '{path}'.

What it means

This is the generic catch-all in FileSystemStore.GetFileStreamAsync(path): any exception other than FileStoreException while resolving or opening the file (File.OpenRead failures such as UnauthorizedAccessException, IOException, path-format errors) is wrapped in a FileStoreException with this message. The original exception is preserved as InnerException. It signals an unexpected failure reading the file, distinct from the explicit 'does not exist' check.

Solutions

  1. Inspect exception.InnerException to identify the real cause (UnauthorizedAccessException vs IOException vs ArgumentException).
  2. Grant the application identity read permission on the file store root directory.
  3. Sanitize/normalize the path (reject invalid characters, excessive length) before passing it to GetFileStreamAsync.
  4. Retry the open on IOException if a transient lock (antivirus/indexer) is suspected; otherwise fail gracefully with a 500.

Example fix

// before
var stream = await _fileStore.GetFileStreamAsync(path);

// after
try
{
    var stream = await _fileStore.GetFileStreamAsync(path);
}
catch (FileStoreException ex) when (ex.InnerException is UnauthorizedAccessException)
{
    _logger.LogError(ex, "No read permission for '{Path}'", path);
    return Forbid();
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (string.IsNullOrWhiteSpace(path) || path.Contains('"') || path.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
{
    throw new ArgumentException("Invalid store path", nameof(path));
}

Try / catch

try
{
    return await fileStore.GetFileStreamAsync(path);
}
catch (FileStoreException ex)
{
    logger.LogError(ex.InnerException ?? ex, "Could not open '{Path}' from file store", path);
    throw;
}

Prevention

When it happens

Trigger: GetFileStreamAsync(path) where GetPhysicalPath or File.OpenRead throws — e.g. unauthorized access, file locked by another process (IOException), path too long, invalid characters in path, or disk I/O failure.

Common situations: App pool identity lacks NTFS read permission on App_Data/media folders; antivirus or another worker holds the file open; path contains illegal characters from user input; directory unexpectedly removed mid-operation on network shares.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


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

Appendix: source

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

        {
            var physicalPath = GetPhysicalPath(path);

            if (!File.Exists(physicalPath))
            {
                throw new FileStoreException($"Cannot get file stream because the file '{path}' does not exist.");
            }

            var stream = File.OpenRead(physicalPath);

            return Task.FromResult<Stream>(stream);
        }
        catch (FileStoreException)
        {
            throw;
        }
        catch (Exception ex)
        {
            throw new FileStoreException($"Cannot get file stream of the file '{path}'.", ex);
        }
    }

    public Task<Stream> GetFileStreamAsync(IFileStoreEntry fileStoreEntry)
    {
        try
        {
            var physicalPath = GetPhysicalPath(fileStoreEntry.Path);
            if (!File.Exists(physicalPath))
            {
                throw new FileStoreException($"Cannot get file stream because the file '{fileStoreEntry.Path}' does not exist.");
            }

            var stream = File.OpenRead(physicalPath);

            return Task.FromResult<Stream>(stream);
        }
        catch (FileStoreException)

View on GitHub (pinned to 4306c0717f)