web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Unable to cast object of type 'System.Guid' to type 'Microsoft.Xrm.Sdk.EntityReference'

(0) ShareShare
ReportReport
Posted on by

I have the following  code

OrganizationServiceProxy serviceProxy = GetOrganizationService();
Entity lead = new Entity("lead");
EntityReference accountLookup = new EntityReference
{
Id = accountId,
LogicalName = "account"
};
EntityReference ownerLookup = new EntityReference
{
Id = aePrimary,
LogicalName = "systemuser"
};
//lead.Attributes["parentaccountid"] = accountLookup;
lead.Attributes["ds_aeprimary"] = aePrimary;
lead.Attributes["ownerid"] = ownerLookup;
lead.Attributes.Add("ds_projecttype", new OptionSetValue(projectType));

  Guid response = serviceProxy.Create(lead);

I am getting the Unable to cast object of type 'System.Guid' to type 'Microsoft.Xrm.Sdk.EntityReference' after upgrading sdk from 6 to 8. I went through article in this community and on google but nothing helped. Please help Thanks!

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Michel van den Brink Profile Picture
    4,697 on at

    Hello,

    What type is your field 'ds_aeprimary'?

    That's the only field I can see where your code is trying to write a GUID.

  • Verified answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Hi Jack,

    A few questions:

    What data type is ds_aeprimary? Not in your code?

    Seems like the issue is there as you are trying to put it in the owner lookup.

    Should that be an entityreference as well instead of a Guid?

  • Community Member Profile Picture
    on at

    Yes it is. That's the problem. Thanks!

  • Suggested answer
    Community Member Profile Picture
    on at

    Yes That is the problem. Thanks!

  • Michel van den Brink Profile Picture
    4,697 on at

    Any time, here to help! :-)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans