1

We use ASP.NET webapi2 and have lot of jsonconverters implemented as part of our models.

We rarely get below exception, approx once a month. We don't use any validation attribute on our models. After reviewing there code many times not sure,what is causing it.

Has anybody face similar exceptions before, any clues.

Collection was modified; enumeration operation may not execute.

at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) at System.Collections.Generic.Dictionary2.Enumerator.MoveNext() at System.Web.Http.Validation.DefaultBodyModelValidator.ValidateElements(IEnumerable model, ValidationContext validationContext) at System.Web.Http.Validation.DefaultBodyModelValidator.ValidateNodeAndChildren(ModelMetadata metadata, ValidationContext validationContext, Object container, IEnumerable1 validators) at System.Web.Http.Validation.DefaultBodyModelValidator.ValidateProperties(ModelMetadata metadata, ValidationContext validationContext) at System.Web.Http.Validation.DefaultBodyModelValidator.ValidateNodeAndChildren(ModelMetadata metadata, ValidationContext validationContext, Object container, IEnumerable1 validators) at System.Web.Http.Validation.DefaultBodyModelValidator.ValidateProperties(ModelMetadata metadata, ValidationContext validationContext) at System.Web.Http.Validation.DefaultBodyModelValidator.ValidateNodeAndChildren(ModelMetadata metadata, ValidationContext validationContext, Object container, IEnumerable1 validators) at System.Web.Http.ModelBinding.FormatterParameterBinding.d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.HttpActionBinding.d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ExceptionFilterResult.d__0.MoveNext()

Pravin
  • 810
  • 1
  • 10
  • 17

2 Answers2

0

Yes, that error normally means that say you had a list of something that amounted to the following:

A
B
C

Something is inserting something into the list in a way that is causing the list to be modified like so:

A
B
D
C

for example. The enumeration throws an exception because it recognized the list was modified; this can commonly happen in a foreach loop. See this post for more info: Collection was modified; enumeration operation may not execute in ArrayList as an example. Using for is a way to get around it.

Did you customize any part of the model binding strategy?

Community
  • 1
  • 1
Brian Mains
  • 50,520
  • 35
  • 148
  • 257
0

I have disabled, model binding module. As we don't need it. To avoid this exceptions.

Pravin
  • 810
  • 1
  • 10
  • 17