ND0001: Avoid runtime type loading

Summary

ND0001 warns when code uses System.Type.GetType(...), which is often fragile under trimming and NativeAOT.

Why this matters

  • Type.GetType(string) relies on runtime name-based type loading.
  • Trimming can remove unreferenced types, causing runtime failures.
  • NativeAOT favors compile-time type closure and explicit references.

Trigger example

var type = Type.GetType(typeName);

Prefer one of these patterns:

  • Use compile-time known types:
var type = typeof(MyType);
  • Use explicit generic registration/factory APIs that keep types rooted.
  • Pass Type values directly instead of names when possible.

Diagnostic details

  • ID: ND0001
  • Category: NativeData.Compatibility
  • Default severity: Warning
  • Message: Runtime type loading with Type.GetType is not AOT/trimming-safe

Suppression guidance

Suppress only when runtime loading is intentional and validated for deployment targets.