I'm retrieving some data from CRM 2011. I have a windows form application with a service reference to my organization.
query = new QueryByAttribute();
query.EntityName = "myentityname";
cset = new ColumnSet();
cset.AllColumns = true;
cset.Columns = new string[] { "" };
query.ColumnSet = cset;
query.Attributes = new string[] { "col1", "col2" };
query.Values = new object[] { col1.value, col2.value };
result = (EntityCollection)_service.RetrieveMultiple(query);
The "retrieveMultiple" threw the exception below :
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:RetrieveMultipleResult. The InnerException message was 'Error in line 1 position 833.
Element 'http://schemas.datacontract.org/2004/07/System.Collections.Generic:value' contains data from a type that maps to the name 'http://schemas.microsoft.com/xrm/2011/Contracts:OptionSetValue'.
The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver or add the type corresponding
to 'OptionSetValue' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'.
Please see InnerException for more details.
I did some search online and ended up removed "cset.AllColumns=true; and replace the "" in the query.columns with one of the column names for this entity. This worked fine but then the rest of my code causes an error.
if (result.Entities.Length > 0)
{
Entity myentity= new Entity();
myentity.LogicalName = "EntityName";
myentity.Attributes = new AttributeCollection();
//record exists, update
myentity.Id = (result.Entities[0]).Id;
myentity.Attributes.Add(new KeyValuePair<string, object> ("myentityid", ((Entity)result.Entities[0]).Id));
_service.Update(myentity);
}
This time "update" method throws this exception:
There was an error while trying to serialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:entity.
The InnerException message was 'Type 'CRM_Populi_Integration.CRMSer.EntityReference' with data contract name 'EntityReference:http://schemas.microsoft.com/xrm/2011/Contracts' is not expected.
Consider using a DataContractResolver or 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.'.
Please see InnerException for more details.
I don't understand the reason behind this serielization error and I don't know how to fix it.
Note: This application was working fine on another server, I just copied and pasted the application in another server and updated the service reference and it's when these exceptions started to appear.
Can you help me with it ?
Thanks