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

Announcements

No record found.

News and Announcements icon
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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans