Saturday, 16 May 2015

There was an error while trying to deserialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:query. The InnerException message was 'Error in line x position y. Element 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:anyType' contains data from a type that maps to the name 'System.Collections.Generic:List`1'

When you do the ConditionOperator.In in your Query during perfoming RetrieveMultiple, you might encounter this error.

“The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:query. The InnerException message was 'Error in line x position y. Element 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:anyType' contains data from a type that maps to the name 'System.Collections.Generic:List`1'. The deserializer has no knowledge of any type that maps to this name. Consider changing the implementation of the ResolveName method on your DataContractResolver to return a non-null value for name 'List`1' and namespace 'System.Collections.Generic'.'.  Please see InnerException for more details.”

Well, here is the way how I solve this.

Root Cause

Actually, the Root Cause is because I was passing the List<object> rather than an Array, which resulted to the error.

Solution

I just change my code

From:

List<Guid> guidMyIds = new List<Guid>();
//I call the function to return list of Guid's
guidMyIds = GetGuidList();
qx.Criteria.AddCondition("guid", ConditionOperator.In, guidMyIds);

Then I change to
List<Guid> guidMyIds = new List<Guid>();
//I call the function to return list of Guid's
guidMyIds = GetGuidList();
qx.Criteria.AddCondition("guid", ConditionOperator.In, guidMyIds.ToArray());

I just change the list to array and now it works.

guidMyIds.ToArray()

Hope this helps!

Thanks!

No comments:

Post a Comment

My Name is..