ND0003: Avoid string-based runtime activation
Summary
ND0003 warns when code uses string-based Activator.CreateInstance(...) overloads.
Why this matters
- String-based activation depends on runtime type/assembly resolution.
- Trimming and NativeAOT can remove or rewrite metadata paths these calls depend on.
- This pattern can fail in published/AOT environments even if it works in local debug runs.
Trigger example
var instance = Activator.CreateInstance(assemblyName, typeName);
Recommended fixes
Prefer one of these patterns:
- Use compile-time known types:
var instance = Activator.CreateInstance(typeof(MyType));
- Use explicit factories or DI registrations for known concrete types.
- Avoid name-based activation paths for production AOT/trimming scenarios.
Diagnostic details
- ID:
ND0003 - Category:
NativeData.Compatibility - Default severity:
Warning - Message:
String-based activation with Activator.CreateInstance is not AOT/trimming-safe
Suppression guidance
Suppress only when runtime activation is required and deployment/runtime behavior is explicitly validated.