Collection was modified; enumeration operation may not execute Archives - Microsoft Dynamics 365 Blog https://microsoftdynamics.in/tag/collection-was-modified-enumeration-operation-may-not-execute/ Microsoft Dynamics CRM . Microsoft Power Platform Thu, 09 Jul 2020 17:28:29 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/04/cropped-Microsoftdynamics365-blogs.png?fit=32%2C32&ssl=1 Collection was modified; enumeration operation may not execute Archives - Microsoft Dynamics 365 Blog https://microsoftdynamics.in/tag/collection-was-modified-enumeration-operation-may-not-execute/ 32 32 176351444 ERROR : Collection was modified; enumeration operation may not execute – While converting Entity Collection To List https://microsoftdynamics.in/2020/07/09/error-collection-was-modified-enumeration-operation-may-not-execute-while-converting-entity-collection-to-list/ Thu, 09 Jul 2020 17:28:29 +0000 http://microsoftdynamics.in/?p=3883 I recently Show 1 of my old note with this error which was pending for post, so thought of sharing it,

While converting EntityRefrence to List- Entity and then processing this List-Entity in For-each Loop got below error
Collection was modified; enumeration operation may not execute

Back then at 1st Glance it was not clear what was the error but debugging it pointed the issue,

Code with the Error:  Error is with ForEach Loop in dictionary object 

The post ERROR : Collection was modified; enumeration operation may not execute – While converting Entity Collection To List<Entity> appeared first on Microsoft Dynamics 365 Blog.

]]>

I recently Show 1 of my old note with this error which was pending for post, so thought of sharing it,

While converting EntityRefrence to List- Entity and then processing this List-Entity in For-each Loop got below error

Collection was modified; enumeration operation may not execute

Back then at 1st Glance it was not clear what was the error but debugging it pointed the issue,

  • Code with the Error:  Error is with ForEach Loop in dictionary object 
EntityCollection nonMandatoryProcessRule = FetchAllProcessRules(organizationService, serviceTypeGUID, categoryTypeGUID, departmentTypeGUID, CustomerTypeBOOL, false , 0);
          
            List<Entity> nonMandatoryProcessRuleLIST = new List<Entity>(nonMandatoryProcessRule.Entities);
          
            foreach (Entity processRuleRecordET in nonMandatoryProcessRuleLIST)
            {
                if (!ValidateProcessRuleConditions.ValidateProcessRuleCondition(processRuleRecordET, currentEntityET , organizationService))
                {
                    try
                    {
                        nonMandatoryProcessRuleLIST.Remove(processRuleRecordET);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Error in removing " + processRuleRecordET+"  check  " + ex.Message);
                    }
                }
            }
  • Code after Resolving the Error

The post ERROR : Collection was modified; enumeration operation may not execute – While converting Entity Collection To List<Entity> appeared first on Microsoft Dynamics 365 Blog.

]]>
3883