{"record":{"id":"d8bff647010e03fc","repo":"OrchardCMS/OrchardCore","slug":"filepath","errorCode":null,"errorMessage":"{filePath}","messagePattern":"\\{filePath\\}","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Infrastructure/Scripting/Files/FilesScriptEngine.cs","lineNumber":32,"sourceCode":"        return new FilesScriptScope(fileProvider, basePath);\n    }\n\n    public object Evaluate(IScriptingScope scope, string script)\n    {\n        ArgumentNullException.ThrowIfNull(scope);\n\n        if (scope is not FilesScriptScope fileScope)\n        {\n            throw new ArgumentException($\"Expected a scope of type {nameof(FilesScriptScope)}\", nameof(scope));\n        }\n\n        if (script.StartsWith(\"text('\", StringComparison.Ordinal) && script.EndsWith(\"')\", StringComparison.Ordinal))\n        {\n            var filePath = script[6..^2];\n            var fileInfo = fileScope.FileProvider.GetRelativeFileInfo(fileScope.BasePath, filePath);\n            if (!fileInfo.Exists)\n            {\n                throw new FileNotFoundException(filePath);\n            }\n\n            using var fileStream = fileInfo.CreateReadStream();\n            using var streamReader = new StreamReader(fileStream);\n            return streamReader.ReadToEnd();\n        }\n        else if (script.StartsWith(\"base64('\", StringComparison.Ordinal) && script.EndsWith(\"')\", StringComparison.Ordinal))\n        {\n            var filePath = script[8..^2];\n            var fileInfo = fileScope.FileProvider.GetRelativeFileInfo(fileScope.BasePath, filePath);\n            if (!fileInfo.Exists)\n            {\n                throw new FileNotFoundException(filePath);\n            }\n\n            using var fileStream = fileInfo.CreateReadStream();\n            using var memoryStream = MemoryStreamFactory.GetStream();\n            memoryStream.WriteTo(fileStream);","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Infrastructure/Scripting/Files/FilesScriptEngine.cs#L14-L50","documentation":"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.","triggerScenarios":"Evaluating a script text('somefile.txt') where no file matching that relative path exists under the scope's BasePath.","commonSituations":"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.","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."],"exampleFix":"// before\nvar result = engine.Evaluate(scope, \"text('Template.txt')\"); // file is template.txt on Linux\n// after\nvar result = engine.Evaluate(scope, \"text('template.txt')\");","handlingStrategy":"try-catch","validationCode":"var fi = fileScope.FileProvider.GetRelativeFileInfo(fileScope.BasePath, path);\nif (!fi.Exists) return null; // or substitute a default","typeGuard":null,"tryCatchPattern":"try { content = engine.Evaluate(scope, $\"text('{path}')\"); }\ncatch (FileNotFoundException) { content = fallbackContent; }","preventionTips":["Verify files exist relative to the scope BasePath before evaluating","Remember Linux case sensitivity","Include required files in deployment/App_Data"],"tags":["scripting","file-not-found","io"],"backgroundTag":"file-not-found","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}