Archive

Archive for September 2, 2014

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

   [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

{}

Check Entities attribute type – CRM Late Binding

September 2, 2014 Leave a comment

Recently somebody posted a question in my blog, whether there is a way to determine the entities ‘Attribute Type’ instead of making Organization service call and read the metadata. 

Assume you have a Plug-in you made a ‘Retrieve’ call using Late Binding and, you got Entity object. 

Below is easy way to determine type of each attribute using ‘is’ operator.

Entity.Attributes[attributeName] is EntityReference

Or

Entity.Attributes[attributeName] is Money

Or

Entity.Attributes[attributeName] is OptionSetValue

🙂

Categories: CRM Tags: , ,