OrchardCMS/OrchardCore · error · ArgumentException
Unknown command
Error message
Unknown command '{script}' What it means
Evaluate in the Files scripting engine fell through all known script forms ('base64(...)' and other prefixes) and reached the final else branch, meaning the script string did not match any supported command syntax. The offending input is the script expression itself, e.g. a typo'd or unsupported command name.
Solutions
- Rewrite the script to the exact form text('path') or base64('path') with single quotes and no extra whitespace.
- If the script is JavaScript or Liquid, route it to the appropriate IScriptingEngine instead of the Files engine.
- Validate/normalize the script string (trim, correct quoting) before calling Evaluate.
Example fix
// before
engine.Evaluate(scope, "text(\"file.txt\")"); // wrong quotes -> unknown command
// after
engine.Evaluate(scope, "text('file.txt')"); Defensive patterns
Strategy: validation
Validate before calling
var ok = (script.StartsWith("text('") && script.EndsWith("')")) ||
(script.StartsWith("base64('") && script.EndsWith("')"));
if (!ok) throw new FormatException("Files scripts must be text('path') or base64('path')."); Try / catch
try { result = engine.Evaluate(scope, script); }
catch (ArgumentException ex) when (ex.Message.StartsWith("Unknown command")) { /* route to the correct engine */ } Prevention
- Use single quotes and no surrounding whitespace in Files scripts
- Only send text()/base64() scripts to FilesScriptEngine
- Dispatch scripts by prefix to the right IScriptingEngine
When it happens
Trigger: Calling Evaluate on the Files engine with a script that is neither text('...') nor base64('...') — e.g. bare paths, wrong quotes, extra whitespace, or scripts meant for another engine (JS, Liquid).
Common situations: Authoring script strings with double quotes instead of single quotes; passing expressions like shell('...') or js('...') to the Files engine; trailing spaces breaking the EndsWith check.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Cannot convert to TimeSpan
- Invalid switch syntax
- Expected a scope of type
- {filePath}
- string.Join(", ", result.Errors)
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/b3faf61d5d0b263b.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.Infrastructure/Scripting/Files/FilesScriptEngine.cs:57
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);
memoryStream.Seek(0, SeekOrigin.Begin);
return Convert.ToBase64String(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);
}
else
{
throw new ArgumentException($"Unknown command '{script}'");
}
}
}
View on GitHub (pinned to 4306c0717f)