<declaredTypes>

Contains the known types that the DataContractSerializer uses when deserializing.

For more information about data contracts and known types, see Data Contract Known Types.

system.runtime.serialization
<dataContractSerializer>
<declaredTypes>

Syntax

<configuration>  
  <system.runtime.serialization>  
    <dataContractSerializer>  
      <declaredTypes>  
        <add type="String ">  
          <knownType type="String">  
                <parameter index="Integer"/>  
          </knownType>  
        </add>  
      </declaredTypes>  
    <dataContractSerializer>  
  </system.runtime.serialization>  
</configuration>  

Attributes and Elements

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

Attributes

None.

Child Elements

Element Description
<add> Adds types that require known types.

Parent Elements

Element Description
<dataContractSerializer> Contains configuration data for the DataContractSerializer.

Remarks

For more information about known types, see Data Contract Known Types and DataContractSerializer.

Example

The following XML code shows declared types and known types added to a DataContractSerializer element. The example shows three types being added. The first is a custom type named "Orders" that uses a known type named "Item". The second declared type is a List<T> that uses Item as a known type. Finally the third declared type is a Dictionary<TKey,TValue>. The Dictionary<TKey,TValue> class type is a generic type, with two type parameters. The first represents the key and the second represents the value. The following example adds a List<T> of the second type (the value) to the list of known types. You must use the index attribute to specify which type parameter to use in the known type. In this case, the value type is indicated by the index attribute set to "1" (the collection is zero-based).

<configuration>  
  <system.runtime.serialization>  
    <dataContractSerializer>  
      <declaredTypes>  
        <add type="Examples.Types.Orders, SerializationTypes, Version = 2.0.0.0, Culture = neutral, PublicKeyToken=null">  
          <knownType type="Examples.Types.Item, SerializationTypes, Version=2.0.0.0, Culture=neutral, PublicKey=null" />  
        </add>  
        <add type="System.Collections.Generic.List`1, SerializationTypes, Version = 2.0.0.0, Culture = neutral, PublicKeyToken=null">  
          <knownType type="Examples.Types.Item, SerializationTypes, Version=2.0.0.0, Culture=neutral, PublicKey=null" />  
        </add>  
        <add type="System.Collections.Generic.Dictionary`2, SerializationTypes, Version = 2.0.0.0, Culture = neutral, PublicKeyToken=null">  
          <knownType type="System.Collections.Generic.List`1, SerializationTypes, Version = 2.0.0.0, Culture = neutral, PublicKeyToken=null">  
            <parameter index="1"/>  
          </knownType>  
        </add>  
      </declaredTypes>  
    <dataContractSerializer>  
  </system.runtime.serialization>  
</configuration>  

See Also

DataContractSerializer
<dataContractSerializer>
Data Contract Known Types
<add>