I get an error when trying to get Systemuser information from Dynamics CRM 2011. The following code works:
public List<CrmUser> GetAllCrmUsers() { List<CrmUser> CrmUsers = new List<CrmUser>(); using (CrmSdk.OrganizationServiceClient myCrm = new CrmSdk.OrganizationServiceClient("CustomBinding_IOrganizationService1")) { try { // this will need to be changed... the address to a key in the app.config and the credentials will need to be whatever is correct for the // end server to hit the CRM WCF service myCrm.Endpoint.Address = new System.ServiceModel.EndpointAddress("https://devcrm.removed/XRMServices/2011/Organization.svc"); myCrm.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials; CrmSdk.ColumnSet colsPrincipal = new CrmSdk.ColumnSet(); colsPrincipal.Columns = new string[] { "lastname", "firstname", "domainname", "systemuserid" }; CrmSdk.QueryExpression queryPrincipal = new CrmSdk.QueryExpression(); queryPrincipal.EntityName = "systemuser"; queryPrincipal.ColumnSet = colsPrincipal; CrmSdk.EntityCollection myAccounts = myCrm.RetrieveMultiple(queryPrincipal); foreach (CrmSdk.Entity myEntity in myAccounts.Entities) { //create new crm users and add it to the list CrmUser thisOne = new CrmUser(); thisOne.firstName = myEntity.Attributes[0].Value.ToString(); thisOne.lastName = myEntity.Attributes[1].Value.ToString(); thisOne.userId = myEntity.Attributes[2].Value.ToString(); thisOne.userGuid = myEntity.Attributes[3].Value.ToString(); CrmUsers.Add(thisOne); } } catch (Exception ex) { CrmUser thisOne = new CrmUser(); thisOne.firstName = "Crap there was an error"; thisOne.lastName = ex.ToString(); CrmUsers.Add(thisOne); } } return CrmUsers; }
However, if I try to add "businessunitid" to the ColumnSet when the service is called, I get an error message:
"Error in line 1 position 1879. Element \ 2004/07 / System.Collections.Generic: value \ 'contains data from a type that maps to the name \' / xrm / 2011 / Contracts: OptionSetValue \ '. The deserializer does not know any the 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, using the KnownTypeAttribute attribute or adding it to the list of known types passed to the DataContractSerializer. \ '"
This error is due to the fact that the returned data is of the “Search” type according to the metadata information . I tried to add [KnownType(typeof(OptionSetValue))] only under the [Data Contract] tag, but no problem, and I’ve been on Google and Binging (?) For two days now, so if it has already been answered, I bring my apologies.
source share