I have the following structure:
public class DerivedClass : List<BaseClass>
{
//Some helper methods used against the List of BaseClass properties
//Methods
public List<BaseClass> GetListOfBaseClasses()
{
return (List<BaseClass>)this;
}
}
My WCF service knows about the BaseClass object, but the client derived it as a generic list, now when I try to call the service, like this:
DerivedClass classD;
FillData(classD)
List<BaseClass> baseClassList = classD.GetListOfBaseClasses();
using (IService myService = ObjectFactory.GetMyService())
{
myService.DoSomething(baseClassList); //Method is expecting "List<BaseClass>"
}
I get the following exception:
Type 'DerivedClass' with data contract name '[some URI text]' 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.
I tried adding these attributes to my class in various combinations but still no luck:
[Serializable]
[KnownType(typeof(List<BaseClass>))]
[XmlInclude(typeof(List<BaseClass>))]
[KnownType(typeof(BaseClass))]
[XmlInclude(typeof(BaseClass))]
public class DerivedClass : List<BaseClass>
{
/// ...
}
PS- Sheehs, am I the only one that thinks the entry fields are funky on this site? Things keep moving around as I try to format... :| great site regardless of my inability to get the idea of entering text as I want.