Posts Tagged ‘DataContractSerializer’

Expecting element from namespace encountered with name namespace – Error DataContractSerializer

September 2, 2014 Leave a comment

I have a REST  enabled WCF service with Method GetFruits() which return list of Fruit objects serialized in XML format.

My ‘Fruit’ class defined as below


public class Fruit   {

string name = string.Empty;


public string Name       {

get { return name; }

set { name = value; }



I built a Client Web application and try to execute the ‘GetFruits’ and get the Fruit collection.

I got the result XML but when I try to DeSerialize XML to List<Fruit> I got below error


  • Namespace of ‘Fruit’ class at Service and Client are not matching


  • Add ‘Namespace’ tag to ‘Fruit’ class in both Client & Server.

[DataContract(Namespace = “ABC”)]

public class Fruit