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 :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Value cannot be null. Parameter name: item

(0) ShareShare
ReportReport
Posted on by 10

Hi All,

We are using Dynamics CRM  and we try to retrieve values with the query.
Time to time we are receiving an error message like "Value cannot be null. Parameter name: item".
What we noticed is that this error occur either in context.OrganizationService.RetrieveMultiple(...) or context.OrganizationService.Retrieve(...) methods.
This methods are part of Microsoft.Xrm.Sdk.IOrganizationService:

Example of the code where the error occur: 

                    EntityCollection results = context.OrganizationService.RetrieveMultiple(
                        new QueryExpression
                        {
                            EntityName = Contact.EntityLogicalName,
                            ColumnSet = new ColumnSet(Contact.Fields.CustomField),
                            Criteria =
                            {
                                Filters =
                                {
                                    new FilterExpression
                                    {
                                        FilterOperator = LogicalOperator.And,
                                        Conditions =
                                        {
                                            new ConditionExpression(Contact.Fields.ContactId, ConditionOperator.Equal, contactId),
                                        }
                                    }
                                }
                            },
                        }
                    );



LogTrace:
pastedimage1678454447328v1.png

Any inputs will be highly appreciated.

I have the same question (0)
  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Can you please provide the code where you instantiate/set the variable with the name contactId?

  • Oleksandra Tolkachova Profile Picture
    10 on at

    The contactId is GUID with the id of the contact. We set this value in this variable above.

    We have also a check for null and empty value before we start with RetrieveMultiple.

    if (contactId != null && contactId != Guid.Empty)
    {
          EntityCollection results = context.OrganizationService.RetrieveMultiple( new QueryExpression { .... } );
    }

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Then I would recommend profiling the execution of your plugin using Plugin profiler, replay and see what's wrong with the query.

    learn.microsoft.com/.../tutorial-debug-plug-in

  • Oleksandra Tolkachova Profile Picture
    10 on at

    The problem that we cannot simulate the same issue on our side.

    The query is correct, we have tried  to debug it and use logging to see what kind value was send in RetrieveMultiple() method. Everything looks okay.

    The error occur on Microsoft.XRM.SDK side. What is trigger it is unclear.

    This error is not reproducible locally and not consistent.

    It is somewhat similar or related to the error 'Collection was modified; enumeration operation may not execute.'

    The 2 errors coming in different time from the same part of the code related to get value with query using RetrieveMultiple() method

    1) Type: 'System.ArgumentNullException',

        Message: 'Value cannot be null. Parameter name: item',

    2) Type: 'System.InvalidOperationException',

        Message: 'Collection was modified; enumeration operation may not execute.',

  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    that code can be changed with a Retrieve because you are retrieving a single contact by the id, however try with this simpler version of the code and check if you still get the same error or not:

    QueryExpression queryContact = new QueryExpression("contact");
    queryContact.ColumnSet = new ColumnSet("contactid"); // add your custom field here
    queryContact.Criteria.AddCondition("contactid", ConditionOperator.Equal, contactId);
    EntityCollection results = context.OrganizationService.RetrieveMultiple(queryContact);

    if it works it means something in your variables is not correct

    the single retrieve version would be:

    Entity contact = context.OrganizationService.Retrieve("contact", contactId, new ColumnSet("contactid")); // add your custom field inside ColumnSet

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 43 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans