Ecng.Compilation
1.0.253
dotnet add package Ecng.Compilation --version 1.0.253
NuGet\Install-Package Ecng.Compilation -Version 1.0.253
<PackageReference Include="Ecng.Compilation" Version="1.0.253" />
<PackageVersion Include="Ecng.Compilation" Version="1.0.253" />
<PackageReference Include="Ecng.Compilation" />
paket add Ecng.Compilation --version 1.0.253
#r "nuget: Ecng.Compilation, 1.0.253"
#:package Ecng.Compilation@1.0.253
#addin nuget:?package=Ecng.Compilation&version=1.0.253
#tool nuget:?package=Ecng.Compilation&version=1.0.253
Ecng.Compilation
Dynamic code compilation infrastructure for C#, F#, and Python. Compile code at runtime, manage references, and cache assemblies.
Overview
This library provides a unified interface for runtime code compilation supporting multiple languages through specialized providers.
Core Types
ICompiler Interface
The main abstraction for compilers.
public interface ICompiler
{
string Extension { get; } // e.g., ".cs", ".fs", ".py"
bool IsAssemblyPersistable { get; } // Can save compiled assembly
bool IsTabsSupported { get; } // Language supports tabs
bool IsCaseSensitive { get; } // Language is case-sensitive
bool IsReferencesSupported { get; } // Supports external references
ICompilerContext CreateContext();
Task<CompilationResult> Compile(
string name,
IEnumerable<string> sources,
IEnumerable<(string name, byte[] body)> refs,
CancellationToken ct = default);
Task<CompilationError[]> Analyse(
object analyzer,
IEnumerable<object> analyzerSettings,
string name,
IEnumerable<string> sources,
IEnumerable<(string name, byte[] body)> refs,
CancellationToken ct = default);
}
CompilationResult
Result of a compilation operation.
var result = await compiler.Compile("MyCode", sources, references);
if (result.HasErrors)
{
foreach (var error in result.Errors)
{
Console.WriteLine($"{error.Type}: {error.Message}");
Console.WriteLine($" Line {error.Line}, Column {error.Column}");
}
}
else
{
// Get compiled assembly
Assembly assembly = result.Assembly;
// Or get as bytes for storage
byte[] assemblyBytes = result.AssemblyBytes;
}
CompilationError
Represents a compilation error or warning.
public class CompilationError
{
public CompilationErrorTypes Type { get; } // Error, Warning, Info
public string Id { get; } // e.g., "CS0001"
public string Message { get; }
public int Line { get; }
public int Column { get; }
}
Reference Types
AssemblyReference
Reference to a .NET assembly.
// From file path
var fileRef = new AssemblyReference("path/to/assembly.dll");
// From loaded assembly
var loadedRef = new AssemblyReference(typeof(SomeClass).Assembly);
NuGetReference
Reference to a NuGet package.
var nugetRef = new NuGetReference
{
PackageId = "Newtonsoft.Json",
Version = "13.0.1"
};
Compiler Provider
Manages available compilers and provides access to them.
// Get registered compilers
IEnumerable<ICompiler> compilers = CompilerProvider.Compilers;
// Get compiler by extension
ICompiler csCompiler = CompilerProvider.GetCompiler(".cs");
ICompiler fsCompiler = CompilerProvider.GetCompiler(".fs");
ICompiler pyCompiler = CompilerProvider.GetCompiler(".py");
Compiler Implementations
| Package | Language | Extension |
|---|---|---|
| Ecng.Compilation.Roslyn | C# | .cs |
| Ecng.Compilation.FSharp | F# | .fs |
| Ecng.Compilation.Python | Python | .py |
Expression Formulas
Parse and evaluate mathematical expressions at runtime.
using Ecng.Compilation.Expressions;
// Parse expression
var formula = ExpressionHelper.Parse("(a + b) * 2");
// Get variables used
IEnumerable<string> vars = formula.Variables; // ["a", "b"]
// Evaluate with values
var values = new Dictionary<string, decimal>
{
["a"] = 10,
["b"] = 5
};
decimal result = formula.Calculate(values); // 30
Supported Operations
- Arithmetic:
+,-,*,/,% - Comparison:
<,>,<=,>=,==,!= - Logical:
&&,||,! - Functions:
abs,sqrt,min,max,pow, etc.
Assembly Load Context
Manage assembly loading for isolation.
using Ecng.Compilation;
// Track loaded assemblies
var tracker = new AssemblyLoadContextTracker();
// Load assembly in isolated context
var context = tracker.CreateContext("MyPlugin");
Assembly asm = context.LoadFromAssemblyPath("plugin.dll");
// Unload when done
tracker.Unload("MyPlugin");
Compiler Cache
Cache compiled assemblies for reuse.
public interface ICompilerCache
{
bool TryGet(string key, out byte[] assembly);
void Set(string key, byte[] assembly);
void Remove(string key);
void Clear();
}
Usage Examples
Compile C# Code
var compiler = CompilerProvider.GetCompiler(".cs");
string code = @"
public class Calculator
{
public int Add(int a, int b) => a + b;
}";
var result = await compiler.Compile(
name: "Calculator",
sources: new[] { code },
refs: Array.Empty<(string, byte[])>());
if (!result.HasErrors)
{
var type = result.Assembly.GetType("Calculator");
var instance = Activator.CreateInstance(type);
var method = type.GetMethod("Add");
int sum = (int)method.Invoke(instance, new object[] { 2, 3 });
Console.WriteLine(sum); // 5
}
Compile with References
var refs = new List<(string, byte[])>();
// Add reference
var asmBytes = File.ReadAllBytes("MyLibrary.dll");
refs.Add(("MyLibrary.dll", asmBytes));
var result = await compiler.Compile("MyCode", sources, refs);
NuGet
Install-Package Ecng.Compilation
Install-Package Ecng.Compilation.Roslyn # For C# support
Install-Package Ecng.Compilation.FSharp # For F# support
Install-Package Ecng.Compilation.Python # For Python support
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Ecng.ComponentModel (>= 1.0.389)
-
net6.0
- Ecng.ComponentModel (>= 1.0.389)
NuGet packages (6)
Showing the top 5 NuGet packages that depend on Ecng.Compilation:
| Package | Downloads |
|---|---|
|
StockSharp.Algo
Trading algorithms. More info on web site https://stocksharp.com/store/ |
|
|
Ecng.Compilation.Roslyn
Ecng system framework |
|
|
Ecng.Roslyn
Ecng system framework |
|
|
Ecng.Compilation.Python
Ecng system framework |
|
|
Ecng.Compilation.FSharp
Ecng system framework |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Ecng.Compilation:
| Repository | Stars |
|---|---|
|
StockSharp/StockSharp
Algorithmic trading and quantitative trading open source platform to develop trading robots (stock markets, forex, crypto, bitcoins, and options).
|
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.253 | 0 | 12/24/2025 |
| 1.0.252 | 59 | 12/22/2025 |
| 1.0.251 | 69 | 12/21/2025 |
| 1.0.250 | 221 | 12/19/2025 |
| 1.0.249 | 216 | 12/19/2025 |
| 1.0.248 | 340 | 12/17/2025 |
| 1.0.247 | 401 | 12/16/2025 |
| 1.0.246 | 322 | 12/15/2025 |
| 1.0.245 | 310 | 12/15/2025 |
| 1.0.244 | 280 | 12/14/2025 |
| 1.0.243 | 218 | 12/14/2025 |
| 1.0.242 | 226 | 12/13/2025 |
| 1.0.241 | 217 | 12/13/2025 |
| 1.0.240 | 213 | 12/12/2025 |
| 1.0.239 | 176 | 12/12/2025 |
| 1.0.238 | 180 | 12/12/2025 |
| 1.0.237 | 175 | 12/12/2025 |
| 1.0.236 | 171 | 12/12/2025 |
| 1.0.235 | 181 | 12/12/2025 |
| 1.0.234 | 172 | 12/12/2025 |
| 1.0.233 | 848 | 12/2/2025 |
| 1.0.232 | 736 | 12/2/2025 |
| 1.0.231 | 735 | 12/2/2025 |
| 1.0.230 | 353 | 11/30/2025 |
| 1.0.229 | 195 | 11/29/2025 |
| 1.0.228 | 201 | 11/28/2025 |
| 1.0.227 | 204 | 11/28/2025 |
| 1.0.226 | 264 | 11/27/2025 |
| 1.0.225 | 352 | 11/24/2025 |
| 1.0.224 | 273 | 11/24/2025 |
| 1.0.223 | 271 | 11/23/2025 |
| 1.0.222 | 244 | 11/23/2025 |
| 1.0.221 | 330 | 11/22/2025 |
| 1.0.220 | 560 | 11/20/2025 |
| 1.0.219 | 509 | 11/18/2025 |
| 1.0.218 | 470 | 11/18/2025 |
| 1.0.217 | 465 | 11/13/2025 |
| 1.0.216 | 354 | 11/10/2025 |
| 1.0.215 | 1,238 | 11/1/2025 |
| 1.0.214 | 338 | 10/28/2025 |
| 1.0.213 | 343 | 10/27/2025 |
| 1.0.212 | 292 | 10/27/2025 |
| 1.0.211 | 223 | 10/25/2025 |
| 1.0.210 | 267 | 10/24/2025 |
| 1.0.209 | 466 | 10/20/2025 |
| 1.0.208 | 488 | 10/12/2025 |
| 1.0.207 | 256 | 10/11/2025 |
| 1.0.206 | 547 | 10/7/2025 |
| 1.0.205 | 368 | 10/6/2025 |
| 1.0.204 | 580 | 10/3/2025 |
| 1.0.203 | 385 | 10/1/2025 |
| 1.0.202 | 297 | 10/1/2025 |
| 1.0.201 | 321 | 9/30/2025 |
| 1.0.200 | 347 | 9/28/2025 |
| 1.0.199 | 381 | 9/25/2025 |
| 1.0.198 | 2,830 | 9/5/2025 |
| 1.0.197 | 394 | 9/2/2025 |
| 1.0.196 | 1,117 | 8/30/2025 |
| 1.0.195 | 373 | 8/30/2025 |
| 1.0.194 | 410 | 8/20/2025 |
| 1.0.193 | 300 | 8/20/2025 |
| 1.0.192 | 345 | 8/19/2025 |
| 1.0.191 | 363 | 8/15/2025 |
| 1.0.190 | 2,490 | 7/16/2025 |
| 1.0.189 | 768 | 7/14/2025 |
| 1.0.188 | 379 | 7/13/2025 |
| 1.0.187 | 318 | 7/13/2025 |
| 1.0.186 | 307 | 7/12/2025 |
| 1.0.185 | 640 | 7/8/2025 |
| 1.0.184 | 615 | 7/4/2025 |
| 1.0.183 | 356 | 7/2/2025 |
| 1.0.182 | 769 | 6/24/2025 |
| 1.0.181 | 1,389 | 6/16/2025 |
| 1.0.180 | 503 | 6/9/2025 |
| 1.0.179 | 393 | 6/8/2025 |
| 1.0.178 | 781 | 5/25/2025 |
| 1.0.177 | 357 | 5/21/2025 |
| 1.0.176 | 337 | 5/21/2025 |
| 1.0.175 | 300 | 5/17/2025 |
| 1.0.174 | 297 | 5/17/2025 |
| 1.0.173 | 308 | 5/17/2025 |
| 1.0.172 | 839 | 5/12/2025 |
| 1.0.171 | 429 | 5/12/2025 |
| 1.0.170 | 381 | 5/12/2025 |
| 1.0.169 | 331 | 5/11/2025 |
| 1.0.168 | 318 | 5/11/2025 |
| 1.0.167 | 294 | 5/10/2025 |
| 1.0.166 | 281 | 5/10/2025 |
| 1.0.165 | 303 | 5/3/2025 |
| 1.0.164 | 464 | 4/17/2025 |
| 1.0.163 | 423 | 4/15/2025 |
| 1.0.162 | 346 | 4/12/2025 |
| 1.0.161 | 380 | 4/9/2025 |
| 1.0.160 | 1,596 | 3/22/2025 |
| 1.0.159 | 367 | 3/20/2025 |
| 1.0.158 | 339 | 3/20/2025 |
| 1.0.157 | 337 | 3/19/2025 |
| 1.0.156 | 1,299 | 2/26/2025 |
| 1.0.155 | 322 | 2/26/2025 |
| 1.0.154 | 1,532 | 2/8/2025 |
| 1.0.153 | 312 | 2/8/2025 |
| 1.0.152 | 308 | 2/8/2025 |
| 1.0.151 | 326 | 2/6/2025 |
| 1.0.150 | 312 | 2/6/2025 |
| 1.0.149 | 327 | 2/6/2025 |
| 1.0.148 | 319 | 2/6/2025 |
| 1.0.147 | 308 | 2/6/2025 |
| 1.0.146 | 346 | 2/5/2025 |
| 1.0.145 | 337 | 2/5/2025 |
| 1.0.144 | 334 | 2/5/2025 |
| 1.0.143 | 365 | 2/3/2025 |
| 1.0.142 | 318 | 2/2/2025 |
| 1.0.141 | 328 | 2/1/2025 |
| 1.0.140 | 344 | 1/31/2025 |
| 1.0.139 | 331 | 1/30/2025 |
| 1.0.138 | 342 | 1/26/2025 |
| 1.0.137 | 437 | 1/21/2025 |
| 1.0.136 | 319 | 1/21/2025 |
| 1.0.135 | 352 | 1/20/2025 |
| 1.0.134 | 311 | 1/20/2025 |
| 1.0.133 | 409 | 1/19/2025 |
| 1.0.132 | 354 | 1/19/2025 |
| 1.0.131 | 460 | 1/17/2025 |
| 1.0.130 | 340 | 1/17/2025 |
| 1.0.129 | 390 | 1/14/2025 |
| 1.0.128 | 617 | 1/12/2025 |
| 1.0.127 | 403 | 1/12/2025 |
| 1.0.126 | 407 | 1/12/2025 |
| 1.0.125 | 421 | 1/12/2025 |
| 1.0.124 | 402 | 1/12/2025 |
| 1.0.123 | 377 | 1/12/2025 |
| 1.0.122 | 382 | 1/12/2025 |
| 1.0.121 | 398 | 1/11/2025 |
| 1.0.120 | 428 | 1/10/2025 |
| 1.0.119 | 438 | 1/10/2025 |
| 1.0.118 | 436 | 1/9/2025 |
| 1.0.117 | 361 | 1/9/2025 |
| 1.0.116 | 344 | 1/9/2025 |
| 1.0.115 | 360 | 1/9/2025 |
| 1.0.114 | 1,567 | 12/27/2024 |
| 1.0.113 | 402 | 12/19/2024 |
| 1.0.112 | 423 | 11/20/2024 |
| 1.0.111 | 1,246 | 11/18/2024 |
| 1.0.110 | 646 | 11/7/2024 |
| 1.0.109 | 289 | 11/7/2024 |
| 1.0.108 | 322 | 11/7/2024 |
| 1.0.107 | 290 | 11/7/2024 |
| 1.0.106 | 294 | 11/7/2024 |
| 1.0.105 | 287 | 11/7/2024 |
| 1.0.104 | 297 | 11/7/2024 |
| 1.0.103 | 318 | 11/6/2024 |
| 1.0.102 | 322 | 10/31/2024 |
| 1.0.101 | 411 | 10/19/2024 |
| 1.0.100 | 1,001 | 10/12/2024 |
| 1.0.99 | 651 | 10/9/2024 |
| 1.0.98 | 581 | 10/5/2024 |
| 1.0.97 | 1,280 | 9/18/2024 |
| 1.0.96 | 339 | 9/17/2024 |
| 1.0.95 | 1,019 | 9/3/2024 |
| 1.0.94 | 327 | 9/1/2024 |
| 1.0.93 | 1,501 | 8/8/2024 |
| 1.0.92 | 2,552 | 6/12/2024 |
| 1.0.91 | 788 | 5/28/2024 |
| 1.0.90 | 1,418 | 5/4/2024 |
| 1.0.89 | 1,013 | 4/23/2024 |
| 1.0.88 | 323 | 4/21/2024 |
| 1.0.87 | 374 | 4/14/2024 |
| 1.0.86 | 1,195 | 3/28/2024 |
| 1.0.85 | 390 | 3/17/2024 |
| 1.0.84 | 1,388 | 2/23/2024 |
| 1.0.83 | 360 | 2/23/2024 |
| 1.0.82 | 1,112 | 2/18/2024 |
| 1.0.81 | 307 | 2/18/2024 |
| 1.0.80 | 310 | 2/16/2024 |
| 1.0.79 | 949 | 2/13/2024 |
| 1.0.78 | 780 | 2/8/2024 |
| 1.0.77 | 1,048 | 2/5/2024 |
| 1.0.76 | 326 | 2/4/2024 |
| 1.0.75 | 1,064 | 1/23/2024 |
| 1.0.74 | 312 | 1/23/2024 |
| 1.0.73 | 1,025 | 1/12/2024 |
| 1.0.72 | 1,144 | 1/2/2024 |
| 1.0.71 | 365 | 12/29/2023 |
| 1.0.70 | 1,340 | 12/15/2023 |
| 1.0.69 | 429 | 12/15/2023 |
| 1.0.68 | 393 | 12/13/2023 |
| 1.0.67 | 421 | 12/13/2023 |
| 1.0.66 | 2,374 | 11/12/2023 |
| 1.0.65 | 432 | 11/10/2023 |
| 1.0.64 | 406 | 11/10/2023 |
| 1.0.63 | 402 | 11/9/2023 |
| 1.0.62 | 420 | 11/3/2023 |
| 1.0.61 | 425 | 11/1/2023 |
| 1.0.60 | 433 | 11/1/2023 |
| 1.0.59 | 4,129 | 9/8/2023 |
| 1.0.58 | 385 | 9/8/2023 |
| 1.0.57 | 388 | 9/8/2023 |
| 1.0.56 | 457 | 9/8/2023 |
| 1.0.55 | 416 | 9/8/2023 |
| 1.0.54 | 410 | 9/7/2023 |
| 1.0.53 | 517 | 9/3/2023 |
| 1.0.52 | 570 | 8/21/2023 |
| 1.0.51 | 557 | 8/15/2023 |
| 1.0.50 | 491 | 8/14/2023 |
| 1.0.49 | 471 | 8/14/2023 |
| 1.0.48 | 486 | 8/10/2023 |
| 1.0.47 | 3,832 | 7/1/2023 |
| 1.0.46 | 499 | 6/29/2023 |
| 1.0.45 | 2,078 | 5/27/2023 |
| 1.0.44 | 559 | 5/21/2023 |
| 1.0.43 | 584 | 5/19/2023 |
| 1.0.42 | 2,396 | 5/8/2023 |
| 1.0.41 | 608 | 5/1/2023 |
| 1.0.40 | 592 | 4/22/2023 |
| 1.0.39 | 588 | 4/21/2023 |
| 1.0.38 | 4,268 | 4/3/2023 |
| 1.0.37 | 711 | 3/27/2023 |
| 1.0.36 | 765 | 3/21/2023 |
| 1.0.35 | 742 | 3/13/2023 |
| 1.0.34 | 621 | 3/12/2023 |
| 1.0.33 | 666 | 3/11/2023 |
| 1.0.32 | 2,194 | 3/6/2023 |
| 1.0.31 | 740 | 2/26/2023 |
| 1.0.30 | 2,533 | 2/21/2023 |
| 1.0.29 | 732 | 2/20/2023 |
| 1.0.28 | 759 | 2/15/2023 |
| 1.0.27 | 768 | 2/14/2023 |
| 1.0.26 | 3,294 | 2/9/2023 |
| 1.0.25 | 2,395 | 2/7/2023 |
| 1.0.24 | 800 | 2/4/2023 |
| 1.0.23 | 2,542 | 2/2/2023 |
| 1.0.22 | 2,588 | 1/30/2023 |
| 1.0.21 | 842 | 1/18/2023 |
| 1.0.20 | 5,169 | 12/30/2022 |
| 1.0.19 | 859 | 12/23/2022 |
| 1.0.18 | 820 | 12/23/2022 |
| 1.0.17 | 22,922 | 12/12/2022 |
| 1.0.16 | 66,300 | 11/11/2022 |
| 1.0.15 | 2,661 | 11/11/2022 |
| 1.0.14 | 5,077 | 11/5/2022 |
| 1.0.13 | 29,151 | 11/1/2022 |
| 1.0.12 | 26,868 | 10/16/2022 |
| 1.0.11 | 58,819 | 9/8/2022 |
| 1.0.10 | 3,002 | 9/8/2022 |
| 1.0.9 | 2,949 | 9/8/2022 |
| 1.0.8 | 99,246 | 8/24/2022 |
| 1.0.7 | 17,160 | 7/26/2022 |
| 1.0.6 | 103,196 | 7/18/2022 |
| 1.0.5 | 111,242 | 4/30/2022 |
| 1.0.4 | 23,810 | 3/29/2022 |
| 1.0.3 | 462,411 | 12/29/2021 |
| 1.0.2 | 31,361 | 12/20/2021 |
| 1.0.1 | 63,318 | 12/6/2021 |
| 1.0.0 | 4,283 | 12/2/2021 |