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

  • Michel van den Brink Profile Picture
    4,697 on at
    RE: Unable to cast object of type 'System.Guid' to type 'Microsoft.Xrm.Sdk.EntityReference'

    Any time, here to help! :-)

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Unable to cast object of type 'System.Guid' to type 'Microsoft.Xrm.Sdk.EntityReference'

    Yes That is the problem. Thanks!

  • Community Member Profile Picture
    on at
    RE: Unable to cast object of type 'System.Guid' to type 'Microsoft.Xrm.Sdk.EntityReference'

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

  • Verified answer
    Aric Levin - MVP Profile Picture
    30,188 Moderator on at
    RE: Unable to cast object of type 'System.Guid' to type 'Microsoft.Xrm.Sdk.EntityReference'

    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?

  • Verified answer
    Michel van den Brink Profile Picture
    4,697 on at
    RE: Unable to cast object of type 'System.Guid' to type 'Microsoft.Xrm.Sdk.EntityReference'

    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.

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans