Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

RetrieveAttributeResponse NullPointerException

(0) ShareShare
ReportReport
Posted on by 60

In my CRM custom plugin, when I ran an exact piece of code to retrieve optionset values in different functions, one of which encountered the following error:

Exception thrown: 'System.NullReferenceException' in program.exe

I have no idea why this is happening, as I do not have any other declarations of objects in between them,

Person Class

class PersonHandler
{
    Helper helper = new Helper();
    public void ProcessCase(DataRow row)
    {
        if (!(AreAllColumnsEmpty(row)))
        {
            if (condition)
            {
                Console.WriteLine(personEntity);       //Person
                Console.WriteLine(person.gender);      //gender_fieldname
                Console.WriteLine(row[Excel.gender]);  //M
                var exists = helper.GetOptionSetValue(personEntity, person.gender, excelValue); //NullReferenceException
            }
            else
            {
                CreateNew(row);
            }
        }
    }
        
    public void CreateNew(DataRow row)
    {
        Console.WriteLine(personEntity);       //Person
        Console.WriteLine(person.gender);      //gender_fieldname
        Console.WriteLine(row[Excel.gender]);  //M
        var exists = helper.GetOptionSetValue(personEntity, person.gender, excelValue);  //no errors!
    }
}



Helper Class

public class Helper
{
    private OrganizationServiceProxy _proxy;
    private IOrganizationService _org;

    public int GetOptionSetValue(string entityName, string attributeName, string optionLabel)
    {
        RetrieveAttributeRequest retrieveAttributeRequest = new
        RetrieveAttributeRequest
        {
            EntityLogicalName = entityName,
            LogicalName = attributeName,
            RetrieveAsIfPublished = true
        };
        RetrieveAttributeResponse retrieveAttributeResponse = (RetrieveAttributeResponse)_org.Execute(retrieveAttributeRequest); //error-ed out at this statement
        ...
        return 0;
    }
}

  • Suggested answer
    RE: RetrieveAttributeResponse NullPointerException

    Hy,

    In addition to above, _org object is also null and not initialized. It needs to be initialized.

    You can refer this article : https://carldesouza.com/connecting-dynamics-365-organization-service-proxy/

    Thanks,

    Ankit Sabharwal

  • a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: RetrieveAttributeResponse NullPointerException

    Hello,

    There is no entity with schema name that is equal to "Person".

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February 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... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,432 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans