.NET Native serialization code missing for List<T>

464 Views Asked by At

In a Windows 10 Universal app I'm getting an error when trying to use the DataContractSerializer

Type 'System.Collections.Generic.List`1[System.SByte]' cannot be serialized, serialization code for the type is missing.Consult the SDK documentation for adding it as a root serialization type.

I'm not using the DCS directly, but within the context of a WCF call to a service operation.

I haven't been able to work out what runtime directive(s) would fix this problem. The following doesn't help:

<Type Name="System.Collections.Generic.List{System.SByte}" 
      Dynamic="Required Public" 
      DataContractSerializer="Required Public" 
      Browse="Required All" 
      Serialize="Required All"/>
2

There are 2 best solutions below

1
On

According to the documentation (https://msdn.microsoft.com/en-us/library/dn627478(v=vs.110).aspx), your declaration of List<SByte> is incorrect. You only have to indicate the number of generic parameters, not their actual type:

<Type Name="System.Collections.Generic.List`1" ... />
5
On

Maybe this will help:

<Namespace Name="System" Serialize="Required Public" DataContractSerializer="Required All"/>

<Namespace Name="'System.Collections.Generic" DataContractSerializer="Required All">
  <TypeInstantiation Name="List"
        Arguments="System.SByte" Serialize="Public" DataContractSerializer="Required All"/>
</Namespace>

In a similar situation it helped me. I used these links: