OrchardCMS/OrchardCore · error · FileStoreException
Cannot get file stream because the file
Error message
Cannot get file stream because the file '{path}' does not exist. What it means
FileSystemStore.GetFileStreamAsync throws FileStoreException when the requested store-relative path does not map to an existing file on disk. Before opening the stream the store calls GetPhysicalPath(path) and checks File.Exists; if absent, it throws this error instead of returning a null stream. It is a guard so callers get a consistent exception type from the IFileStore abstraction rather than a raw FileNotFoundException.
Solutions
- Call await fileStore.GetFileInfoAsync(path) and verify it is not null (and not a directory) before requesting the stream.
- Verify the path is store-relative (no leading slash, no app-root or absolute filesystem path) — GetPhysicalPath prefixes the store root, so absolute or double-rooted paths resolve to non-existent locations.
- Check the file actually exists on disk under the store root and that the process identity has read access to that directory.
- Wrap the call in try/catch on FileStoreException and fall back to a 404/default-asset response when the file is optional.
Example fix
// before
var stream = await _fileStore.GetFileStreamAsync(model.UserSuppliedPath);
// after
var file = await _fileStore.GetFileInfoAsync(model.UserSuppliedPath);
if (file == null || file.IsDirectory)
{
return NotFound();
}
var stream = await _fileStore.GetFileStreamAsync(file.Path); Defensive patterns
Strategy: validation
Validate before calling
var fileInfo = await fileStore.GetFileInfoAsync(path);
if (fileInfo is null || fileInfo.IsDirectory)
{
// treat as missing: skip, return 404, etc.
return;
} Type guard
static bool FileExists(IFileStore store, string path) => store.GetFileInfoAsync(path).GetAwaiter().GetResult() is { IsDirectory: false }; Try / catch
try
{
var stream = await fileStore.GetFileStreamAsync(path);
using (stream) { /* ... */ }
}
catch (FileStoreException ex)
{
logger.LogWarning(ex, "File '{Path}' not found in store", path);
return Results.NotFound();
} Prevention
- Always resolve paths through IFileStore APIs, never concatenate absolute filesystem paths yourself.
- Check GetFileInfoAsync before opening streams in request handlers.
- Remember Linux case sensitivity — keep media paths canonical.
- Use the IFileStoreEntry overload only with freshly fetched entries.
When it happens
Trigger: Calling await fileStore.GetFileStreamAsync(path) with a store-relative path (e.g. 'sites/tenant/media/doc.pdf') whose underlying physical file does not exist — wrong path, deleted file, or a directory path instead of a file path.
Common situations: Path built from user input or a content-item field without checking GetFileInfoAsync first; file deleted by another process or cleanup job between listing and reading; media stored on a different volume/tenant than the one queried; case-sensitivity mismatch on Linux causing the physical path to miss.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- Cannot copy file ' ' because it does not exist.
- Cannot copy file ' ' because it does not exist.
- Cannot get file stream because the file
- Cannot move file ' ' because it does not exist.
- The file ' ' does not exist.
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/d9c60a1f8af1a00a.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.FileStorage.FileSystem/FileSystemStore.cs:315
catch (FileStoreException)
{
throw;
}
catch (Exception ex)
{
throw new FileStoreException($"Cannot copy file '{srcPath}' to '{dstPath}'.", ex);
}
}
public Task<Stream> GetFileStreamAsync(string path)
{
try
{
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)
{View on GitHub (pinned to 4306c0717f)