Path: redb-route/redb.Route/Expressions/ExpressionSandboxViolationException.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route/Expressions/ExpressionSandboxViolationException.cs
----
namespace redb.Route.Expressions;
///
/// Thrown when an expression tries to run code or read outside the message while an
/// scope is open: a method call, a registry object (ref:name) or an environment variable (env:NAME).
///
public sealed class ExpressionSandboxViolationException : InvalidOperationException
{
private const string Where = "the expression runs in a sandbox (a template argument or expr())";
/// Creates the exception for on .
public ExpressionSandboxViolationException(string methodName, Type type)
: base($"Method '{methodName}' on {type.Name} cannot be called here: {Where}, where objects expose their members but never code.")
{
MethodName = methodName;
Written = methodName;
TargetType = type;
}
///
/// Creates the exception for a read the sandbox refuses, named as written: ref:rules (an object of the
/// registry) or env:HOME (the process environment). No method is involved, so the message names the spelling.
///
/// The spelling as the expression writes it.
public ExpressionSandboxViolationException(string written)
: base($"'{written}' cannot be read here: {Where}, which reads the message and its values, not the registry or the process environment.")
{
ArgumentException.ThrowIfNullOrWhiteSpace(written);
MethodName = written;
Written = written;
}
/// The method the expression tried to call; for a refused read, the spelling ().
public string MethodName { get; }
/// What the expression wrote: the method name, or the spelling of a read (ref:rules, env:HOME).
public string Written { get; }
/// The type the method was looked up on; null for a refused read, which calls no method.
public Type? TargetType { get; }
}