Ninject Intermittent exception thrown related to OnePerRequestModule
Asked Answered
D

1

6

I just upgraded an existing implementation of Ninject from 1.5 to 2.0. I'm now seeing an intermittent exception getting thrown when many requests are happening in a short period of time.

Here's the exception that is being thrown.

Type: System.ArgumentException
Message: An item with the same key has already been added.
Source: Ninject
Stack Trace: at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at Ninject.Components.ComponentContainer.CreateNewInstance(Type component, Type implementation)
at Ninject.Components.ComponentContainer.ResolveInstance(Type component, Type implementation)
at Ninject.Components.ComponentContainer.Get(Type component)
at Ninject.Components.ComponentContainer.<CreateNewInstance>b__6(ParameterInfo parameter)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Ninject.Components.ComponentContainer.CreateNewInstance(Type component, Type implementation)
at Ninject.Components.ComponentContainer.ResolveInstance(Type component, Type implementation)
at Ninject.Components.ComponentContainer.Get(Type component)
at Ninject.Components.ComponentContainer.GetT
at Ninject.KernelBase.CreateContext(IRequest request, IBinding binding)
at Ninject.KernelBase.<>c__DisplayClassa.<Resolve>b__6(IBinding binding)
at System.Linq.Enumerable.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource x)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.<CastIterator>d__aa`1.MoveNext()
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
at Ninject.ResolutionExtensions.Get[T](IResolutionRoot root, IParameter[] parameters)
at NameOfConsumingSite.Application_BeginRequest(Object sender, EventArgs e)...

The exception does not get thrown if I remove the OnePerRequestModule item from httpModules in web.config, but that is adding a ton of overhead.

I thank anyone in advance if they can help!

Domenicadomenico answered 1/10, 2010 at 18:6 Comment(2)
Anything interesting about your bindings? Or is it a stack of implicit class self bindings? In principle, this obviously should just work. Do you have the trunk version or do you have some binary?Quarterphase
Nothing fancy, they're the same bindings that worked flawlessly in v1.5. Also, I'm using the current binary. Sean Chambers from the Ninject Google Group suggests that OnePerRequestModule is deprecated since the InXxxxScope methods handle that responsibility. What is left unanswered is why OnePerRequestModule is still included in the Ninject solution. I also wonder if this may being caused by a racing condition with GarbageCollectionCachePruner.Domenicadomenico
E
3

There was a multithreading problem. Try to use the 2.2 RC1 found at https://github.com/ninject . Please tell me if this problem still occurs with this version to make sure we have no further issue we have to fix before release.

Excellent answered 29/11, 2010 at 0:37 Comment(1)
The specific issue is described (with steps to reproduce) here: github.com/ninject/ninject/issues/closed#issue/17. It was fixed in version 2.1.0.70.Johnnie

© 2022 - 2024 — McMap. All rights reserved.