web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 180 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 123

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans