c# - Collection was modified; enumeration operation may not execute error? -


 public workflowqaruleset getqarule(int usernumber, int usernumberexternal, string applicationid,          short computernumber, long rulebitid)     {          try         {             if (qarules == null)                 qarules = new list<workflowqaruleset>();              workflowqaruleset wfqarule = qarules.firstordefault(                                                 qarule =>                                                     qarule != null &&                                                     qarule.qarulebits63 != null &&                                                     qarule.qarulebits63 == rulebitid);              if (wfqarule == null)             {                 workflowrulesetapiclient workflowruleapiclient = new workflowrulesetapiclient(system.configuration.configurationmanager.appsettings["service:workflow_management_base_uri"]);                  wfqarule = workflowruleapiclient.getqaruleset(usernumber, usernumberexternal, applicationid, computernumber, rulebitid, workflowtypes.paymentprocessing).firstordefault();              }                 if (wfqarule != null)                 qarules.add(wfqarule);              if (wfqarule != null && wfqarule.qarulebits63 == null)                 logger.warn(string.format("invalid qa rule bits 63, {0}", wfqarule.name));              return wfqarule;           }         catch (exception ex)         {             logger.error("error in getting qa rule set.", ex);             throw ex;         }      } 

here entire code , error

system.invalidoperationexception: collection modified; enumeration operation may not execute. @ system.throwhelper.throwinvalidoperationexception(exceptionresource resource) @ system.collections.generic.list1.enumerator.movenextrare() @ system.collections.generic.list1.enumerator.movenext() @ system.linq.enumerable.firstordefault[tsource](ienumerable1 source, func2 predicate) @ smi.smart.paymentprocessing.busprocess.paymentprocessingbp.getqarule(int32 usernumber, int32 usernumberexternal, string applicationid, int16 computernumber, int64 rulebitid)

above code , error. can 1 verify this?

the getqaruleset or getqarule method may have loop, within loop adding or removing members collection looping through. doing change collection , end enumeration.

modifying collection inside loop, or thread main causes of exception.

if wish add items collection looping through (or remove items) can store items add , items remove in temporary collection , add or subtract them after foreach() loop has finished.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -