Ninject 抛出与 OnePerRequestModule 相关的间歇性异常

发布于 2024-09-25 10:14:54 字数 2024 浏览 2 评论 0原文

我刚刚将 Ninject 的现有实现从 1.5 升级到 2.0。我现在看到当短时间内发生许多请求时会抛出间歇性异常。

这是抛出的异常。

类型: System.ArgumentException
消息:已添加具有相同密钥的项目。
来源: Ninject
堆栈跟踪:位于 System.ThrowHelper.ThrowArgumentException(ExceptionResource 资源)
在 System.Collections.Generic.Dictionary`2.Insert(TKey 键,TValue 值,布尔添加)
在 System.Collections.Generic.Dictionary`2.Add(TKey 键,TValue 值)
在 Ninject.Components.ComponentContainer.CreateNewInstance(类型组件,类型实现)
在 Ninject.Components.ComponentContainer.ResolveInstance(类型组件,类型实现)
在 Ninject.Components.ComponentContainer.Get(类型组件)
在 Ninject.Components.ComponentContainer.b__6(ParameterInfo 参数)
在 System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
在 System.Linq.Buffer`1..ctor(IEnumerable`1 源)
在 System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 源)
在 Ninject.Components.ComponentContainer.CreateNewInstance(类型组件,类型实现)
在 Ninject.Components.ComponentContainer.ResolveInstance(类型组件,类型实现)
在 Ninject.Components.ComponentContainer.Get(类型组件)
在 Ninject.Components.ComponentContainer.GetT
在Ninject.KernelBase.CreateContext(IRequest请求,IBinding绑定)
at Ninject.KernelBase.<>c__DisplayClassa.b__6(IBinding 绑定)
在 System.Linq.Enumerable。<>c__DisplayClass12`3。b__11(TSource x)
在 System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
在 System.Linq.Enumerable.d__aa`1.MoveNext()
在 System.Linq.Enumerable.Single[TSource](IEnumerable`1 源)
在 Ninject.ResolutionExtensions.Get[T](IResolutionRoot 根,IParameter[] 参数)
NameOfConsumingSite.Application_BeginRequest(Object sender, EventArgs e)...

如果我从 httpModules 中删除 OnePerRequestModule 项,则不会引发异常web.config,但这会增加大量的开销。

如果有人可以提供帮助,我提前感谢他们!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青巷忧颜 2024-10-02 10:14:54

存在多线程问题。尝试使用 https://github.com/ninject 中找到的 2.2 RC1。请告诉我此版本是否仍然出现此问题,以确保我们在发布之前没有需要修复的进一步问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文