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 'Microsoft.Xrm.Sdk.OptionSetValue' to type 'System.IConvertible'

(0) ShareShare
ReportReport
Posted on by

Hi 

I am trying to compare the option set value in my  class. but I am getting this error "{"Unable to cast object of type 'Microsoft.Xrm.Sdk.OptionSetValue' to type 'System.IConvertible'."}." can any one please suggest to resolve this problem.please it's very urgent.

here is my code

if(new OptionSetValue(Convert.ToInt32(sa.Attributes["isr_typeofdegree"])).Value== new OptionSetValue(Convert.ToInt32(905080000)).Value)
{

//logic

}

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Daniel Wikell Profile Picture
    2,360 on at

    You are trying to convert sa.Attributes["isr_typeofdegree"] into an int32 but this is not something that can be casted this way. isr_typeofdegree seems to be of type "OptionSetValue" and thus you want to use the Value of it to retrieve the int.

    There's no need to create more wrappers around just the int.

    Your code would be better off doing something like:

    if(((OptionSetValue)sa.Attributes["isr_typeofdegree"]).Value == 905080000) {

    //logic

    }

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