The .NET Native framework has 3 built-in serializers, namely XmlSerializer, DataContractSerializer, and DataContractJsonSerializer. These serializers are non-reflection based serializers, relying on the .NET Native compiler to do the analysis of the application and generate the required serialization code for each type which it can detect is serialized and deserialized at runtime.
In some scenarios the .NET Native compiler cannot detect that a particular type is used in serialization. Your app will encounter an InvalidDataContractException with SerializationCodeIsMissingForType exception at runtime if it attempts to serialize or deserialize a type with missing serialization code. In those cases, you need to describe the root serialization type 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 serialization 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 SerializationCodeIsMissingForType error you're facing. Use the information in the error message along with your knowledge of the code that hit the exception to pick the right answers. If the error message doesn't have helpful information, make sure to rebuild in Debug mode with .NET Native optimization enabled.
A single type
There's no pattern. A single type with the following name:
All types in a namespace
All types within the following namespace:
All types in an assembly
All types in the following assembly:
DataContractSerializer
DataContractJsonSerializer
XmlSerializer
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 <Application>
element of the existing RD.XML.
If you are authoring an RD.XML for a library, replace <Application>
with <Library>
.
©2015 Microsoft