AssemblyReferenceProvider
Controls which assemblies are available to compiled expressions. Used for sandboxing.
public class AssemblyReferenceProvider
Default Behavior
The default provider includes a safe whitelist of common assemblies and excludes dangerous ones.
Included by default:
SystemSystem.CoreSystem.LinqSystem.CollectionsSystem.TextSystem.Text.RegularExpressionsMicrosoft.CSharp
Excluded (dangerous):
System.IO— file system accessSystem.Net— network accessSystem.Reflection— reflection abuseSystem.Diagnostics.Process— process executionSystem.Security— security manipulation
Custom Provider
var provider = new AssemblyReferenceProvider();
provider.AddAssembly(typeof(MyCustomType).Assembly);
var del = compiler.Compile<Func<Customer, bool>>(
"customer.Name.Length > 0",
new[] { "customer" },
referenceProvider: provider
);
Security Note
Even with a whitelist, never compile expressions from untrusted sources without validation. See SECURITY.md for full details.
Related
- ExpressionCompiler — Uses provider
- SECURITY.md — Security guide