ND0002: Avoid runtime assembly loading
Summary
ND0002 warns when code uses System.Reflection.Assembly.Load(string).
Why this matters
Assembly.Load(string)depends on runtime assembly name resolution.- Trimming and NativeAOT reduce support for dynamic runtime loading patterns.
- Name-based loading can fail in published/AOT environments where assemblies are linked differently.
Trigger example
var assembly = Assembly.Load(assemblyName);
Recommended fixes
Prefer one of these patterns:
- Use compile-time references to required types/assemblies.
- Pass known
Typeinstances (for example viatypeof(...)) and avoid name-based assembly loading. - Register plugin types explicitly at compile time instead of dynamic assembly probing.
Diagnostic details
- ID:
ND0002 - Category:
NativeData.Compatibility - Default severity:
Warning - Message:
Runtime assembly loading with Assembly.Load(string) is not AOT/trimming-safe
Suppression guidance
Suppress only when runtime assembly loading is required and deployment/runtime constraints are explicitly validated.