To make your app faster and smaller, the .NET Native compiler performs whole program optimizations that employ static analysis to model the program behavior. The optimizations are similar to those traditionally used when compiling languages like C++. One of the optimizations done by the .NET Native compiler is the removal of types, methods, constructors, properties, events, and fields that are not used.
Since reflection is dynamic in nature, not all reflection use can be determined statically at the time of compilation. Because .NET Native does not presently have a just-in-time compiler to compile the pieces that are missing, everything that can be accessed at runtime needs to be known at the time of compilation. Your app will encounter a MissingMetadataException or MissingRuntimeArtifactException if it attempts to use something that was removed.
If the use of reflection is not simple enough for the optimizer to see through, the .NET Native compiler needs your assistance in describing the use of reflection by means of a Runtime Directive.What are runtime directives?
Runtime Directives provide a way for you to describe what types and members your app needs to have available for reflection purposes. The directives are kept in an XML file with an RD.XML extension that is part of your application package. A default RD.XML file is added to all new universal app projects - look for it in the Properties node (My Project node for Visual Basic) of the Solution Explorer. You can add new runtime directives to it when needed.
If you're a library author that needs to describe the use of reflection within the library, you can embed a Runtime Directives files in your library. Simply add a file with an RD.XML extension to your library project, right-click the file in the Solution Explorer window and select Properties. Set the Build Action property to Embedded Resource and you're good to go.
To learn more about the RD.XML syntax, see RD.XML Reference.
The builder below will help you create a directive that will solve the MissingMetadataException you're facing. Use the information in the MissingMetadataException message along with your knowledge of the code that hit the exception to pick the right answers. If the MissingMetadataException message doesn't have helpful information, make sure to rebuild in Debug mode with .NET Native optimization enabled.
A single method
Namespace qualified name of type containing the method:
Method name (without the '<' and '>'):
Comma-separated generic arguments to instantiate the method:
This preview shows you the runtime directive corresponding to the choices
you made in the left column. If you're adding a directive to an existing RD.XML file,
append the directives under the
<Application> element to the
element of the existing RD.XML.
If you are authoring an RD.XML for a library, replace