Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Unable to cast object of type to type at Microsoft.Xrm.Sdk.Entity.GetAttributeValue

(0) ShareShare
ReportReport
Posted on by 145

Hi,

I am developing a plugin that has a post entity image called "image" , and i'm trying to access one of the crm fields in the relevant entity through this image , the field is called "test score" with schema "new_testscore", this field is floating number. I have generated an early bound entity classes with CrmSvcUtil.exe. but i'm facing this error:

System.InvalidCastException: Unable to cast object of type 'System.Decimal' to type 'System.Nullable`1[System.Double'. at Microsoft.Xrm.Sdk.Entity.GetAttributeValue[T(String attributeLogicalName) at Xrm.Incident.get_new_TestScore()

this is snapshot of my code:

var postImage = context.PostEntityImages["image"].ToEntity();
var testScore = postImage.new_TestScore;

Thank you.

  • dd555 Profile Picture
    65 on at
    RE: Unable to cast object of type to type at Microsoft.Xrm.Sdk.Entity.GetAttributeValue

    I am wondering if you changed new_testScore from an optional to a required field but have not regenerated the early bound code. Have you tried regenerating the early bound code?

  • Suggested answer
    Bipin D365 Profile Picture
    28,977 Moderator on at
    RE: Unable to cast object of type to type at Microsoft.Xrm.Sdk.Entity.GetAttributeValue

    Hi,

    You should first check if new_TestScore field is present in dictionary.

    Your code should look like below.

    var postImage = context.PostEntityImages["image"].ToEntity<custom>();

    if(postImage.Attributes.Contains("new_testscore") && postImage["new_testscore"]!=null)

    var testScore = postImage.new_TestScore;

    Please mark my answer verified if i were helpful

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,095 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,866 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans