Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

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

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

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
    Michel van den Brink 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
    Community Member Microsoft Employee 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
    Community Member Microsoft Employee 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 Profile Picture
    Aric Levin 30,188 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
    Michel van den Brink 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans