Middle · Explain · AOT metadata needs an explicit reachability plan

What does a metadata-preservation annotation establish, and why is a JIT run not an AOT compatibility test?

Think through your answer before opening the explanation.

Runtime & concurrency

Reveal answer and reasoning

An annotation such as DynamicallyAccessedMembers communicates which members a reflected Type value requires to remain available to analysis and deployment tooling. It is not a runtime whitelist, an interface-conformance check, or a request to preserve every possible future plugin. The external lesson applies a public-parameterless-constructor requirement to a bounded activation path and compares it with an explicit known factory.

The supplied ordinary run is JIT-based, so success establishes that desktop path only. A common wrong answer sees an annotation or PublishAot-related source and declares a native artifact tested without publishing one. NativeAOT compatibility requires the intended supported publication, warning review, and execution of the actual output, including relevant missing-registration and failure cases. Direct registration can simplify a bounded design by making reachable constructors explicit, while genuinely dynamic requirements must be tested against an execution model capable of supporting them.

What a strong answer covers

  • Annotations communicate reachability requirements.
  • They do not replace validation or authorization.
  • NativeAOT claims require real publication and execution.

Common pitfall

Calling annotated desktop reflection a tested NativeAOT deployment.

Follow-up questions

  1. What does a constructor annotation not preserve?
  2. Why can unrestricted MakeGenericType complicate native deployment?

Self-review

Choose what to revisit. These marks are your own assessment and are separate from lesson completion.

Primary references

Open lesson and code ↗

← All interview questions