OrchardCMS/OrchardCore · error · FileStoreException

Cannot get file stream of the file

Error message

Cannot get file stream of the file '{fileStoreEntry.Path}'.

What it means

Generic catch-all of the IFileStoreEntry overload of GetFileStreamAsync: any non-FileStoreException error while resolving or opening fileStoreEntry.Path (permissions, IO errors, invalid path characters) is rethrown as FileStoreException with this message and the original exception as InnerException. It indicates an unexpected read failure rather than a missing file.

Solutions

  1. Log and inspect ex.InnerException for the underlying cause.
  2. Fix filesystem permissions for the app identity on the store root.
  3. Normalize/validate the entry's Path (invalid characters, length) before use.
  4. Catch FileStoreException and surface a friendly error instead of a raw 500.

Example fix

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

// after
try
{
    var stream = await _fileStore.GetFileStreamAsync(entry);
}
catch (FileStoreException ex)
{
    _logger.LogError(ex.InnerException, "Failed reading '{Path}'", entry.Path);
    return StatusCode(500);
}
Defensive patterns

Strategy: try-catch

Validate before calling

var fresh = await fileStore.GetFileInfoAsync(entry.Path);
if (fresh is null || fresh.IsDirectory)
{
    throw new InvalidOperationException($"'{entry.Path}' is not a readable file in the store.");
}

Try / catch

try
{
    return await fileStore.GetFileStreamAsync(entry);
}
catch (FileStoreException ex)
{
    logger.LogError(ex.InnerException, "Unexpected error reading '{Path}': {Reason}", entry.Path, ex.InnerException?.Message);
    throw;
}

Prevention

When it happens

Trigger: GetFileStreamAsync(fileStoreEntry) where opening the physical file throws UnauthorizedAccessException, IOException (file locked), ArgumentException (invalid path), or GetPhysicalPath fails for the entry's path.

Common situations: Media folder permissions changed on the server; file held open by another request/upload; entry path corrupted by bad import; disk full or failing when reading from network storage.

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/7906a0c18c7a5925. Report an issue: GitHub.

Appendix: source

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

        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)
        {
            throw;
        }
        catch (Exception ex)
        {
            throw new FileStoreException($"Cannot get file stream of the file '{fileStoreEntry.Path}'.", ex);
        }
    }

    public async Task<string> CreateFileFromStreamAsync(string path, Stream inputStream, bool overwrite = false)
    {
        try
        {
            var physicalPath = GetPhysicalPath(path);

            if (!overwrite && File.Exists(physicalPath))
            {
                throw new FileStoreException($"Cannot create file '{path}' because it already exists.");
            }

            if (Directory.Exists(physicalPath))
            {
                throw new FileStoreException($"Cannot create file '{path}' because it already exists as a directory.");
            }

View on GitHub (pinned to 4306c0717f)