Skip to main content
Source: Al0095AvoidExpressionCompileAnalyzer.cs

Description

Expression.Compile() uses Reflection.Emit which is unavailable in AOT, falling back to a significantly slower interpreted mode.

Bad Code

Expression<Func<int, int>> expr = x => x * 2;
var func = expr.Compile();

Good Code

Func<int, int> func = x => x * 2;
// Or use source-generated alternatives

Properties

  • Category: AOT Testing
  • Severity: Warning
  • Enabled by default: True
  • Code fix available: False

Configuration

dotnet_diagnostic.AL0095.severity = warning