I’m trying to serialize a NameValueCollection over WCF. I keep getting exceptions telling me to add one type after another. After adding them, I finally get
Type ‘System.Object[]’ cannot be added to list of known types since another type ‘System.Collections.ArrayList’ with the same data contract name ‘http://schemas.microsoft.com/2003/10/Serialization/Arrays:ArrayOfanyType‘ is already present.
The contract now looks like this:
[KnownType(typeof(NameValueCollection))]
[KnownType(typeof(CaseInsensitiveHashCodeProvider))]
[KnownType(typeof(CaseInsensitiveComparer))]
[KnownType(typeof(string[]))]
[KnownType(typeof(Object[]))]
[KnownType(typeof(ArrayList))]
[DataContract]
public class MyClassDataBase
{
[DataMember]
public NameValueCollection DataCollection = new NameValueCollection();
}
I really dont know what to do to be able to serialize my NameValueColletion.
Another strange thing is that the compiler warns that the CaseInsensitiveHashCodeProvider is deprecated.
The best idea would be to stop using weak types like
NameValueCollectionandArrayList. UseDictionary<string,string>andList<T>instead.