I am using the following 2 Ninject assemblies in my web project.
Ninject.dll – Version 2.2.0.0
Ninject.Web.dll – Version 2.2.0.4
I have noticed that when I perform load testing on the server I am getting exceptions in my which are pointing to the Ninject
Message: Collection was modified; enumeration operation may not execute. Stack Trace: at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) at System.Collections.Generic.List
1.Enumerator.MoveNextRare() at System.Collections.Generic.List
1.Enumerator.MoveNext() at System.Linq.Enumerable.WhereSelectListIterator2.MoveNext() at Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map[T](IEnumerable
1 series, Action`1 action) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Infrastructure\Language\ExtensionsForIEnumerableOfT.cs:line 22 at Ninject.OnePerRequestModule.DeactivateInstancesForCurrentHttpRequest() in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\OnePerRequestModule.cs:line 63 at Ninject.OnePerRequestModule.b__0(Object o, EventArgs e) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\OnePerRequestModule.cs:line 36 at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
I did find this link from Remo Gloor dated May 11 2011 which says there is a new 2.4 version which has mentioned that the problem will be fixed 2.4 version. I am not sure if this version is released/available yet as I not able to find it. Ninject Runtime Exception occuring frequently - System.InvalidOperationException: Collection was modified; enumeration operation may not execute
Does anybody know the solution to this resolve this Ninject error or know where can I find the 2.4 version?
This is the way I have done the mapping using Version 2.2.0.0 of Ninject
Bind<IMyEntities>().To<MyEntities>().InRequestScope().WithConstructorArgument("connectionString", ConfigurationManager.ConnectionStrings["MyEntities"].ConnectionString);
Using 3.0 I changed it to use
Bind<IMyEntities>().ToConstructor(x => new MyEntities());
or
Bind<IMyEntities>().ToConstructor(x => new MyEntities(ConfigurationManager.ConnectionStrings["MyEntities"].ConnectionString));
or
Bind<IMyEntities>().ToConstructor(x => new MyEntities(new EntityConnection (ConfigurationManager.ConnectionStrings["MyEntities"].ConnectionString)));
After trying all the above mentioned 3 different ways I am still getting the error. Every time the 3rd constructor is getting called somehow.
I am not sure what else to try. I have kind of invested a very good amount of time trying different things and still not coming to a conclusion/resolution.
If I am not able to find/resolve this problem somehow I will have to remove all the Ninjet references all together and go for some other DI's.