OrchardCMS/OrchardCore · error · FileNotFoundException
{filePath}
Error message
{filePath} What it means
When evaluating a text('<path>') script, FilesScriptEngine resolves the path against the scope's FileProvider and BasePath and throws FileNotFoundException if the resolved file does not exist. The exception's message is the file path itself.
Solutions
- Verify the file exists relative to the scope BasePath (case-sensitive on Linux) and fix the path.
- Check the IFileProvider configured in FilesScriptScope points at the right root.
- Pre-check existence via fileScope.FileProvider.GetRelativeFileInfo(...).Exists before evaluating, or catch FileNotFoundException with a fallback.
Example fix
// before
var result = engine.Evaluate(scope, "text('Template.txt')"); // file is template.txt on Linux
// after
var result = engine.Evaluate(scope, "text('template.txt')"); Defensive patterns
Strategy: try-catch
Validate before calling
var fi = fileScope.FileProvider.GetRelativeFileInfo(fileScope.BasePath, path); if (!fi.Exists) return null; // or substitute a default
Try / catch
try { content = engine.Evaluate(scope, $"text('{path}')"); }
catch (FileNotFoundException) { content = fallbackContent; } Prevention
- Verify files exist relative to the scope BasePath before evaluating
- Remember Linux case sensitivity
- Include required files in deployment/App_Data
When it happens
Trigger: Evaluating a script text('somefile.txt') where no file matching that relative path exists under the scope's BasePath.
Common situations: Typo in filename or extension; file expected in the tenant's App_Data but placed elsewhere; case-sensitivity on Linux; file created after the script was authored; wrong BasePath in the scope.
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 create a stream for a directory.
- Error retrieving file info for
- Error creating directory
- Error deleting file
- Cannot copy file ' ' because it does not exist.
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/d8bff647010e03fc.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.Infrastructure/Scripting/Files/FilesScriptEngine.cs:32
return new FilesScriptScope(fileProvider, basePath);
}
public object Evaluate(IScriptingScope scope, string script)
{
ArgumentNullException.ThrowIfNull(scope);
if (scope is not FilesScriptScope fileScope)
{
throw new ArgumentException($"Expected a scope of type {nameof(FilesScriptScope)}", nameof(scope));
}
if (script.StartsWith("text('", StringComparison.Ordinal) && script.EndsWith("')", StringComparison.Ordinal))
{
var filePath = script[6..^2];
var fileInfo = fileScope.FileProvider.GetRelativeFileInfo(fileScope.BasePath, filePath);
if (!fileInfo.Exists)
{
throw new FileNotFoundException(filePath);
}
using var fileStream = fileInfo.CreateReadStream();
using var streamReader = new StreamReader(fileStream);
return streamReader.ReadToEnd();
}
else if (script.StartsWith("base64('", StringComparison.Ordinal) && script.EndsWith("')", StringComparison.Ordinal))
{
var filePath = script[8..^2];
var fileInfo = fileScope.FileProvider.GetRelativeFileInfo(fileScope.BasePath, filePath);
if (!fileInfo.Exists)
{
throw new FileNotFoundException(filePath);
}
using var fileStream = fileInfo.CreateReadStream();
using var memoryStream = MemoryStreamFactory.GetStream();
memoryStream.WriteTo(fileStream);View on GitHub (pinned to 4306c0717f)