DataContractSerializer exception "System.DelegateSerializationHolder+DelegateEntry [...
Hello,
in the microsoft.public.windows.developer.winfx.indigo group I was encouraged to ask my question also here, so I hope this is not seen as cross posting. Here's my problem:
I have an object tree which I want to serialize to disk using the
DataContractSerializer. For complexity reasons I have not defined
specific data contracts for each class but I have marked them
[Serializable].
Now I am getting the following exception:
Type 'System.DelegateSerializationHolder+DelegateEntry' with data
contract name
'DelegateSerializationHolder.DelegateEntry:http://schemas.datacontract.org/2004/07/System'
is not expected. 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 don't know what to add to the KnownTypes list...
Any idea?
thx in advance
Fabian
Hi, I have a similar problem, I'm using netTcpBinding and have an Interface that is used by a service method, the problem is that when I invoke the method, I get the following error.
InnerException {"Type 'Microsoft.ServiceModel.Samples.Person' with data contract name 'Person:http://schemas.datacontract.org/2004/07/Microsoft.ServiceModel.Samples' is not expected. 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."} System.Exception {System.Runtime.Serialization.SerializationException}
The classes used are the following:
public interface IPerson
{
int Id{
get;set;
}} [Serializable]public class Person : IPerson{private int id;private string nombre;private string apellido; public int Id{
get { return id; }set { id = value; }
} public string Apellido{
get { return apellido; }set { apellido = value; }}public Person(){}public Person(string nombre){Nombre = nombre;
}} and the method is:// Define a service contract.
[ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")]public interface ICalculator{
IPerson Save(Person person);}
// Service class which implements the service contract.// Added code to write output to the console windowpublic class CalculatorService : ICalculator{
public IPerson Save(Person p){
IPerson iPerson=(IPerson)p; Console.WriteLine("Received {0}", p.Nombre + " " + p.Apellido);iPerson.Id=1; Console.WriteLine("Return: {0}", iPerson.Id); return iPerson;}// Host the service within this EXE console application.public static void Main(){
// Get base address from app settings in configurationUri baseAddress = new Uri(ConfigurationManager.AppSettings["baseAddress"]);// Create a ServiceHost for the CalculatorService type and provide the base address.using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress)){
// Open the ServiceHostBase to create listeners and start listening for messages.serviceHost.Open();// The service can now be accessed.Console.WriteLine("The service is ready.");Console.WriteLine("Press <ENTER> to terminate service.");Console.WriteLine();Console.ReadLine();}}} How can I solve the problem?
Thanks,
Daniel Andrade