<Assembly> Element (.NET Native)

Applies runtime reflection policy to all the types in a specified assembly.

Syntax

<Assembly Name="assembly_name"
          Activate="policy_setting"
          Browse="policy_setting"
          Dynamic="policy_setting"
          Serialize="policy_setting"
          DataContractSerializer="policy_setting"
          DataContractJsonSerializer="policy_setting"
          XmlSerializer="policy_setting"
          MarshalObject="policy_setting"
          MarshalDelegate="policy_setting"
          MarshalStructure="policy_setting" />

Attributes and Elements

The following sections describe attributes, child elements, and parent elements.

Attributes

Attribute Attribute type Description
Name General Required attribute. Specifies the simple name of an assembly.
Activate Reflection Optional attribute. Controls runtime access to constructors to enable activation of instances.
Browse Reflection Optional attribute. Controls querying for information about or enumerating the types in the assembly, but does not enable any dynamic access at run time.
Dynamic Reflection Optional attribute. Controls runtime access to all type members, including constructors, methods, fields, properties, and events, to enable dynamic programming.
Serialize Serialization Optional attribute. Controls runtime access to constructors, fields, and properties, to enable type instances to be serialized and deserialized by libraries such as the Newtonsoft JSON serializer.
DataContractSerializer Serialization Optional attribute. Controls policy for serialization that uses the System.Runtime.Serialization.DataContractSerializer class.
DataContractJsonSerializer Serialization Optional attribute. Controls policy for JSON serialization that uses the System.Runtime.Serialization.Json.DataContractJsonSerializer class.
XmlSerializer Serialization Optional attribute. Controls policy for XML serialization that uses the System.Xml.Serialization.XmlSerializer class.
MarshalObject Interop Optional attribute. Controls policy for marshaling reference types to Windows Runtime and COM.
MarshalDelegate Interop Optional attribute. Controls policy for marshaling delegate types as function pointers to native code.
MarshalStructure Interop Optional attribute. Controls policy for marshaling structures to native code.

Name attribute

Value Description
assembly_name The simple name of the assembly, without its file extension. This attribute corresponds to the AssemblyName.Name property. For example, the name of an assembly named Extensions.dll is "Extensions".

You can also specify the literal string *Application* to apply policy to all assemblies in your app package, whether those assemblies are loaded or not. *Application* never applies policy to .NET Framework assemblies.

All other attributes

Value Description
policy_setting The setting to apply to this policy type for all types in the assembly. Possible values are All, Auto, Excluded, Public, PublicAndInternal, Required Public, Required PublicAndInternal, and Required All. For more information, see Runtime Directive Policy Settings.

Child Elements

Element Description
<Namespace> Applies reflection policy to all types in a child namespace.
<Type> Applies reflection policy to a type.
<TypeInstantiation> Applies reflection policy to a constructed generic type.

Parent Elements

Element Description
<Application> Serves as a container for application-wide types and type members whose metadata is available for reflection at run time. The <Application> element can have zero, one, or more <Assembly> elements.
<Library> Defines the assembly that contains types and type members whose metadata is available for reflection at run time. The <Library> element can have zero or one <Assembly> element.

Remarks

The <Assembly> element defines runtime policy for all the types in an assembly. It differs from the <Library> element, which specifies a library but depends on its child elements to define runtime reflection policy. The <Assembly> element applies to all the types in an assembly unless they are overridden by a child element.

The following example shows how you can apply runtime policy to all the types in assemblies within your app package by assigning the Name attribute a value of "*Application*". The <Assembly> element must be a child of the <Application> element.

<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
  <Application>
     <Assembly Name="*Application*" Dynamic="Required All" />
  </Application>
</Directives>

The Activate, Browse, Dynamic, and Serialize attributes are all optional. However, the <Assembly> element must contain at least one of these attributes.

See also