Loading…
Loading…
12 карточек
What is Native AOT in .NET and what are its limitations?
нажми, чтобы перевернуть
PublishAot=true: compiles to a native binary without runtime/JIT. Startup: ~10ms vs ~100ms JIT. Size: ~10-15MB self-contained. Limitations: no dynamic loading, limited reflection (only with [DynamicallyAccessedMembers]), no Reflection.Emit, no Assembly.Load. Trimming: removes unused code. Source generators replace reflection. ASP.NET Core Minimal API is compatible with AOT in .NET 8+.
<!-- csproj -->
<PropertyGroup>
<PublishAot>true</PublishAot>
</PropertyGroup>
// JSON без reflection (source generated)
[JsonSerializable(typeof(List<User>))]
public partial class AppJsonContext : JsonSerializerContext { }
// Minimal API + AOT
var builder = WebApplication.CreateSlimBuilder(args);
builder.Services.ConfigureHttpJsonOptions(o =>
o.SerializerOptions.TypeInfoResolverChain
.Insert(0, AppJsonContext.Default));Когда да
Serverless (Lambda/Azure Functions), CLI tools, microservices with cold start requirements
Когда нет
Applications with plugins, dynamic code generation, heavy reflection (some ORMs, DI containers)
Совет на собеседовании
AOT breaks: System.Text.Json without source gen, AutoMapper, some DI containers. Check ILLink warnings.
Свайп вправо — знаю, влево — не знаю
