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

[1068 byte] By [Neutronensturm] at [2007-12-23]
# 1
Hi Fabian,

well, of course it is hard to tell from air - can you post your DTOs and the serializing code here?

Cheers,
Christian

P.S.: Echt cooler Name, Neutronensturm

ChristianWeyer at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 2
Hi Christian,

as I do not know where the problem is located it is not easy to send you an appropriate code snippet. It is somewhere hidden in an instance hierarchy of more than 10 classes of at least 80 lines of code each. I have not tried all the classes but the serialization seems to work on single/independent instances.

Cheers

Fabian

P.S.: Neutronensturm - hatte wohl zu viel Star Trek geschaut .

Neutronensturm at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 3
Hi Fabian,

hm, then I think I am lost and may be not able to help. Sorry.

Cheers,

ChristianWeyer at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 4

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 window

public 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 configuration

Uri 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


NetDragonKing at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 5

This last problem is discussed over here now.

Cheers,

ChristianWeyer at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...

Visual Studio Orcas

Site Classified