Reputation: 1004
I have a DataContract
say called Credentials
which I've inherited into my own business object called MyCredentials
and customized. I want to send it over the wire but understandably I get an error.
There was an error while trying to serialize parameter
Is there a way to resolve this without doing a conversion between business object and DataContracts
? My code work looks something like this
[DataContract]
[KnownType(typeof(Credentials))]
internal class MyCredentials : Credentials
{
public MyCredentials ()
{
}
}
Upvotes: 1
Views: 304
Reputation: 91
Accessibility modifiers do not affect a DataContract after all it is a contract.
Upvotes: 0
Reputation: 35544
You need to decorate the base class Credientials with the KnownType-Attribute.
[DataContract]
[KnownType(typeof(MyCredentials))]
publice class Credentials
{
public Credentials()
{
}
}
Also i think you need to make the class public and not internal when you decorate it with the DataContractAttribute.
[DataContract]
public class MyCredentials : Credentials {
public MyCredentials () {
}
}
Upvotes: 3