Error while retrieving Data from CRM Organization Service: OptionSetValue Deserializer Issue RRS feed

  • 问题

  • Hello,

    i used VS2010 to create a new WCF Service Application. Within this WCF Service Application i want to connect to the CRM Organization Service. So i add a service reference to http://devsrv/devcrm/XRMServices/2011/Organization.svc and wrote the following code:


    OrganizationServiceClient crm = new OrganizationServiceClient();
    crm.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("Administrator", "kennwort", "development");
    ColumnSet cols = new ColumnSet();
    cols.Columns = new string[] { "fullname" };

    Entity contact = crm.Retrieve("contact", new Guid("5B3634A8-81BF-E011-9717-8D4C34E7495A"), cols);


    This code works fine but if i use this ColumnSet instead


    ColumnSet cols = new ColumnSet();
    cols.AllColumns = true;


    I get this error:

    Error in line 1 position 688. 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.


    What is my mistake? What am I doing wrong?
    Is that what I'm trying not possible by this way?


    Thanks & Regards, Martin

    2011年8月5日 21:42


  • Hi Amadeus_64,


    Add below to the Entity class.





    2011年8月8日 15:28


  • 1. you should modify the reference.cs file which is generated when referencing to "http://devsrv/devcrm/XRMServices/2011/Organization.svc".Open the reference.cs file, and add the [KnownType(typeof(OptionSetValue))] attribute for the "Entity" class

    2. you could using crmsvcutil.exe to generate the c sharp code for the target organization, and then import it into the wcf application;


    daemon lin
    2011年8月6日 4:41
  • Hello daemonlin,


    thanks for you answer.


    1) I update the reference.cs as follow (added the bold line):

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "")]
    [System.Runtime.Serialization.DataContractAttribute(Name="Entity", Namespace="http://schemas.microsoft.com/xrm/2011/Contracts")]
    public partial class Entity : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {

    But this doesn't fix the error. :(


    2) I've tried already to implement it, as you suggest. For this i need to update the web.config with a <microsoft.xrm.client>. In an app.config file it works fine, but if i use it in an web.config file, i get a parse error.

    2011年8月6日 15:42
  • Hi Amadeus_64,


    Add below to the Entity class.





    2011年8月8日 15:28
  • You're a hero, Duneel!
    This fixed the problem for me :)

    It strikes me as odd though that this isn't automatically generated when creating the service reference...


    Ruud van Falier

    Blog: http://ruuddottech.blogspot.com

    2012年12月13日 17:52