Im having problems when passing an generic List, trough a WCF operation. In this case, there is a List of int. The example 4 is described here in MSDN. Note that in MSDN sample, is described:
// This will serialize and deserialize successfully because the generic List is equivalent to int[], which was added to known types.
Above, is the DataContract:
[DataContract]
[KnownType(typeof(int[]))]
[KnownType(typeof(object[]))]
public class AccountData
{
[DataMember]
public object accNumber1;
[DataMember]
public object accNumber2;
[DataMember]
public object accNumber3;
[DataMember]
public object accNumber4;
}
In client side, Im calling the operation like this:
DataTransfer.Service.AccountData data = new DataTransfer.Service.AccountData()
{
accNumber1 = 100,
accNumber2 = new int[100],
accNumber3 = new List<int>(),
accNumber4 = new ArrayList()
};
cService.AddAccounts(data);
Also, here is the decorations of the generated AccountData obj (WCF proxy):
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="AccountData", Namespace="http://schemas.datacontract.org/2004/07/DataTransfer.Service")]
[System.SerializableAttribute()]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(DataTransfer.Client.CustomerServiceReference.PurchaseOrder))]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(DataTransfer.Client.CustomerServiceReference.Customer))]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(int[]))]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(object[]))]
The exception is:
There was an error while trying to serialize parameter http://tempuri.org/:myEntity. The InnerException message was 'Type Generic List' with data contract name 'ArrayOfint:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Add any types not known statically to the list of known types