Home
> Misc > Expecting element from namespace encountered with name namespace – Error DataContractSerializer
Expecting element from namespace encountered with name namespace – Error DataContractSerializer
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
[DataContract]
public class Fruit {
string name = string.Empty;
[DataMember]
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
Reason –
- Namespace of ‘Fruit’ class at Service and Client are not matching
Fix –
- Add ‘Namespace’ tag to ‘Fruit’ class in both Client & Server.
[DataContract(Namespace = “ABC”)]
public class Fruit
{}
Categories: Misc
DataContractSerializer, Deserialize, serialize
Comments (0)
Trackbacks (0)
Leave a comment
Trackback