I am trying to send a object via WCF as parameter in this method:
[OperationContract]
bool SendProject(Project project);
and I got this if i try to call it from client:
There was an error while trying to serialize parameter project. The InnerException message was 'Type 'System.Collections.ObjectModel.Collection`1[[System.Collections.DictionaryEntry, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' with data contract name 'ArrayOfDictionaryEntry:http://schemas.datacontract.org/2004/07/System.Collections' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.
I search some info and I think that the error is how I serialize a class (a class from Dr. WPF) which is inside "project" class:
#region ISerializable
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
{
throw new ArgumentNullException("info");
}
Collection<DictionaryEntry> entries = new Collection<DictionaryEntry>();
foreach (DictionaryEntry entry in _keyedEntryCollection)
entries.Add(entry);
info.AddValue("entries", entries);
}
#endregion ISerializable
The problem is that I dont know where to put the tag "KnownType" or how to serialize correctly this Dictionary to send it as parameter using WCF.
Thanks!
DictionaryEntry
is non-generic and so WCF will not know the contracts for the keys and values. But why are you using a non-generic dictionary from .Net 1.1? Why not use a typed model? WCF is designed to work with typed models. Alternatively, if you can't use a typed model, can you share a minimal reproducible example that reproduces the problem? At the moment you just share a code fragment that don't compile standalone. – dbcCollection<DictionaryEntry>
(orCollection<KeyValuePair<string, something you haven't shown us>>
)maybe you can reproduce this with a simpleDictionary<TKey, TValue>
stored inside a root object? – dbc