InvalidOperationException: Collection was modified; enumeration operation may not execute.
See original GitHub issueHi, Windsor, while resolving, throws exceptions like that:
Error details: An error ocurred while executing the step
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
at Castle.Windsor.Proxy.AbstractProxyFactory.ShouldCreateProxy(ComponentModel model)
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstance(CreationContext context, ConstructorCandidate constructor, Object[] arguments)
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context)
at Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden)
at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally)
at Castle.MicroKernel.Lifestyle.SingletonLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy)
at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden)
at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired)
at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, IDictionary additionalArguments, IReleasePolicy policy)
at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy)
at Castle.Windsor.WindsorContainer.Resolve[T]()
at DPF.Common.Step`2.GetRunnerComponents(String jobSettings, String stepSettings)
What leads to function:
public bool ShouldCreateProxy(ComponentModel model)
{
if (model.HasInterceptors)
{
return true;
}
var options = model.ObtainProxyOptions(false);
if (options != null && options.RequiresProxy)
{
return true;
}
if (selectors != null && selectors.Any(s => s.HasInterceptors(model)))
{
return true;
}
return false;
}
Is it problem in windsor or in my project? Shoundn’t it be thread save or something?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Collection was modified; enumeration operation may not ...
So the issue behind this error is, we can not modify the list/dictionary while we are looping through the same. One of the...
Read more >Why the error Collection was modified enumeration ...
This error occurs when a looping process is being running on a collection (Ex: List) and the collection is modified (data added or...
Read more >Collection Was Modified Enumeration Operation May Not ...
The collection was modified enumeration operation may not execute exception occurs when you modify the collection while looping through the same.
Read more >Collection was modified; enumeration operation may not ...
Solution 1 – If you're removing items, use RemoveAll() · Solution 2 – If you're adding items, put them in a temp and...
Read more >enumeration operation may not execute. At foreach
Solution 2. You cannot enumerate a collection in a foreach block and modify the collection in the same block.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey, I’ve encountered similar issue. Has anyone investigated this? Thanks
My stack:
@Mattio91 @Beton no one is investigating this issue because we at least need a repro, something we can run that reproduces the exception.
@neutmute your problem might be the same as this defect but you didn’t include your stack trace to compare, @Mattio91’s makes no mention of WCF anywhere.
We need a repro, however we’d love a pull request with a fix, that’ll guarantee this gets fixed for you guys. The pull request doesn’t need to be perfect, we can work together once we’ve got something.
Without a repro we’ll close this issue in a few days.