locked
CrmEntityReference Serialization Issue RRS feed

  • Question

  • Hi

    We've just implemented XRM on our on-premise CRM 4 (rollup 21) development instance and are currently working through our plugins converting our code. Everything is working fine except for not be able to pass an instance of a CrmEntityReference object. We're using the latest edition of the SDK.

    The exception messages are as follows:

    The following is inner exception info:Source=System.Xml. Message=The type Microsoft.Xrm.Client.CrmEntityReference was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.

    Type 'Microsoft.Xrm.Client.CrmEntityReference' with data contract name 'CrmEntityReference:http://schemas.datacontract.org/2004/07/Microsoft.Xrm.Client' is not expected. 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.

    Has anyone seen this issue before or have any pointers as to how to resolve this?

    Any information you can supply would be greatly appreciated.

    Kind regards,

    Lee

    Friday, August 30, 2013 1:50 PM

All replies

  • Hi,

    Are you getting this exception when calling the SDK Websevices? If so, use an EntityReference and not CrmEntityReference.

    hth,

    Scott


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Monday, September 2, 2013 8:36 AM
    Answerer
  • Hi Scott

    Many thanks for your response.

    Maybe it's my lack of understanding in this area, but, this doesn't work either. I've resolved this by targeting the value property of the entity instead rather than trying to pass an entity reference:

    var activities = (from activity in crm.activitypointers
                        where
                            (activity.statecode == ActivityPointerState.Open.ToString() ||
                            activity.statecode == ActivityPointerState.Scheduled.ToString()) &&
                            activity.regardingobjectid.Value == contactId &&
                            activity.ownerid.Value != owner.PrincipalId
                        select new { activity.activityid, activity.activitytypecode }).ToList();

    Kind regards,

    Lee


    • Edited by Lee Diggins Friday, September 6, 2013 8:55 AM
    Friday, September 6, 2013 8:55 AM
  • Hi,

    Right - I see what's happening then. 

    You have got your earlybound types generated using the Microsoft.Xrm.Client extensions (which means the entities inherit from CrmEntity and not Entity and any references use CrmEntityReferences and not EntityReferences. If you get a record from a LINQ query and then try and make calls to the standard OrganziationsService - you will get the serialisation errors because the CrmEntityReference is not the correct type. 

    Glad you got it sorted.


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Friday, September 6, 2013 9:59 AM
    Answerer