Skip to main content

Documentation Index

Fetch the complete documentation index at: https://ancplua.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

Source: Al0101AvoidActivatorCreateInstanceAnalyzer.cs

Description

Activator.CreateInstance() relies on reflection to create instances, which is not compatible with Native AOT trimming. Use direct construction or factory patterns.

Bad Code

var service = Activator.CreateInstance(typeof(OrderService));

Good Code

var service = new OrderService();
// Or use DI: serviceProvider.GetRequiredService<OrderService>()

Properties

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

Configuration

dotnet_diagnostic.AL0101.severity = warning