Ninject Intermittent exception thrown related to OnePerRequestModule - ninject

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!

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.

Related

Microsoft Orleans, Unsupported type, Serializer not available GrainInterfaceMap

I am trying to connect to an orleans silo but I got this error.
{"Unsupported type 'Orleans.Runtime.GrainInterfaceMap' encountered.
Perhaps you need to mark it [Serializable] or define a custom
serializer for it?"}
at Orleans.Serialization.SerializationManager.DeserializeInner(Type
expected, BinaryTokenStreamReader stream) at
Orleans.Serialization.BuiltInTypes.DeserializeOrleansResponse(Type
expected, BinaryTokenStreamReader stream) at
Orleans.Serialization.SerializationManager.DeserializeInner(Type
expected, BinaryTokenStreamReader stream) at
Orleans.Serialization.SerializationManager.Deserialize(Type t,
BinaryTokenStreamReader stream) at
Orleans.Serialization.SerializationManager.Deserialize(BinaryTokenStreamReader
stream) at Orleans.Runtime.Message.DeserializeBody(List1 bytes)
at Orleans.Runtime.Message.get_BodyObject() at
Orleans.Runtime.GrainReference.ResponseCallback(Message message,
TaskCompletionSource1 context)
When I searched in object browser, I can see a class, possibly created to serialize this class :
Orleans.Runtime.Configuration.OrleansCodeGenOrleans_Runtime_GrainInterfaceMapSerializer.OrleansCodeGenOrleans_Runtime_GrainInterfaceMapSerializer()
But somehow i got this error. I think there is configuration problem.. Do you have any idea about how i can solve this problem?
Thanks..

Ninject + Web ApI 2: Error activating IFilterProvider using binding from IFilterProvider to DefaultFilterProvider

I originally had used some custom code I found to handle the dependency resolution in Web API and it worked fine. The issue I ran into was that I wanted to bind a filter to my controller scopes just like you can with MVC. For example, Kernel.BindFilter. The new Ninject.We.WebApi package has the binding extension I want but as soon as I add it to my project I get the following error. I'm not changing any of my code, just referencing a DLL.
Error activating IFilterProvider using binding from IFilterProvider to
DefaultFilterProvider A cyclical dependency was detected between the
constructors of two services.
Activation path: 3) Injection of dependency IFilterProvider into
parameter defaultFilterProviders of constructor of type
DefaultFilterProviders 2) Injection of dependency
DefaultFilterProviders into parameter filterProviders of constructor
of type DefaultFilterProvider 1) Request for IFilterProvider
Suggestions: 1) Ensure that you have not declared a dependency for
IFilterProvider on any implementations of the service. 2) Consider
combining the services into a single one to remove the cycle. 3) Use
property injection instead of constructor injection, and implement
IInitializable if you need initialization logic to be run after
property values have been injected.
at Ninject.Activation.Context.Resolve() at
Ninject.KernelBase.<>c__DisplayClass15.b__f(IBinding binding)
at System.Linq.Enumerable.WhereSelectListIterator2.MoveNext() at
System.Linq.Enumerable.<CastIterator>d__b11.MoveNext() at
System.Linq.Enumerable.d__142.MoveNext() at
System.Collections.Generic.List1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at
Ninject.Web.WebApi.Filter.DefaultFilterProvider.GetFilters(HttpConfiguration
configuration, HttpActionDescriptor actionDescriptor) at
System.Web.Http.Controllers.HttpActionDescriptor.b__0(IFilterProvider
fp) at
System.Linq.Enumerable.d__142.MoveNext() at
System.Linq.Buffer1..ctor(IEnumerable1 source) at
System.Linq.OrderedEnumerable1.d__0.MoveNext() at
System.Linq.Buffer1..ctor(IEnumerable1 source) at
System.Linq.Enumerable.d__a01.MoveNext() at
System.Web.Http.Controllers.HttpActionDescriptor.<RemoveDuplicates>d__3.MoveNext()
at System.Linq.Buffer1..ctor(IEnumerable1 source) at
System.Linq.Enumerable.<ReverseIterator>d__a01.MoveNext() at
System.Collections.Generic.List1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at
System.Web.Http.Controllers.HttpActionDescriptor.InitializeFilterPipeline()
at System.Lazy1.CreateValue()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
System.Lazy`1.get_Value() at
System.Web.Http.Controllers.HttpActionDescriptor.GetFilterPipeline()
at
System.Web.Http.Controllers.HttpActionDescriptor.GetFilterGrouping()
at System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext
controllerContext, CancellationToken cancellationToken) at
System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncCore(HttpRequestMessage
request, CancellationToken cancellationToken) at
System.Web.Http.Dispatcher.HttpControllerDispatcher.d__0.MoveNext()
In case anyone else is looking for a potential solution for cyclical dependency for the IFilterProvider, I had to explicitly bind DefaultFilterProviders like this
k.Bind<DefaultFilterProviders>().ToConstant(new DefaultFilterProviders(GlobalConfiguration.Configuration.Services.GetFilterProviders()));
or this
k.Bind<DefaultFilterProviders>().ToSelf().WithConstructorArgument(GlobalConfiguration.Configuration.Services.GetFilterProviders());
If anyone else knows a better way I would love to hear it.
I figured it out. I added the Nuget package Ninject.Web.WebApi.WebHost.

Ninject Runtime Exception occuring frequently - System.InvalidOperationException: Collection was modified; enumeration operation may not execute

I am using Ninject 2.2.1.0 with Ninject.Web 2.2.0.0 in a webforms application.
I am getting daily error reports of the following...
System.InvalidOperationException: Collection was modified; enumeration
operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource
resource)
at System.Collections.Generic.List1.Enumerator.MoveNextRare()
at System.Collections.Generic.List1.Enumerator.MoveNext()
at System.Linq.Enumerable.WhereSelectListIterator2.MoveNext()
at Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map[T](IEnumerable1
series, Action`1 action) in
c:\Projects\Ninject\ninject\src\Ninject\Infrastructure\Language\ExtensionsForIEnumerableOfT.cs:line
22
at Ninject.OnePerRequestModule.DeactivateInstancesForCurrentHttpRequest()
in
c:\Projects\Ninject\ninject\src\Ninject\OnePerRequestModule.cs:line
63
at Ninject.OnePerRequestModule.b__0(Object
o, EventArgs e) in
c:\Projects\Ninject\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)
Seems to be occuring at peak times. Is there a stable release with this patched yet?
Creation of kernel instances is not thread safe at the moment. This will probably be changed with 2.4

Raven.Server.exe exception

I've never used RavenDb it looks interesting but I'm falling at the first hurdle.
I've downloaded, unzipped and I run C:\RavenDB\Server\Raven.Server.exe
and it flashes up and disappears.
I tried running from a dos prompt and I got this exception:
C:\RavenDB\Server>Raven.Server.exe
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the
requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.Assembly.GetTypes()
at System.ComponentModel.Composition.Hosting.AssemblyCatalog.get_InnerCatalog
()
at System.ComponentModel.Composition.Hosting.AssemblyCatalog.GetExports(Impor
tDefinition definition)
at System.ComponentModel.Composition.Hosting.AggregateCatalog.GetExports(Impo
rtDefinition definition)
at System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExports
Core(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(Import
Definition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.AggregateExportProvider.GetExpor
tsCore(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore
(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1
& exports)
at System.ComponentModel.Composition.Hosting.CompositionContainer.GetExportsC
ore(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(Import
Definition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ImportEngine.TryGetExports(Expor
tProvider provider, ComposablePart part, ImportDefinition definition, AtomicComp
osition atomicComposition)
at System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImportSub
set(PartManager partManager, IEnumerable`1 imports, AtomicComposition atomicComp
osition)
at System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImportsSt
ateMachine(PartManager partManager, ComposablePart part)
at System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImports(P
artManager partManager, ComposablePart part, Boolean shouldTrackImports)
at System.ComponentModel.Composition.Hosting.ImportEngine.SatisfyImportsOnce(
ComposablePart part)
at System.ComponentModel.Composition.AttributedModelServices.SatisfyImportsOn
ce(ICompositionService compositionService, Object attributedPart)
at Raven.Database.DocumentDatabase..ctor(InMemoryRavenConfiguration configura
tion)
at Raven.Server.RavenDbServer..ctor(RavenConfiguration settings)
at Raven.Server.Program.RunServer(RavenConfiguration ravenConfiguration)
at Raven.Server.Program.RunInDebugMode(Nullable`1 anonymousUserAccessMode, Ra
venConfiguration ravenConfiguration)
at Raven.Server.Program.InteractiveRun(String[] args)
at Raven.Server.Program.Main(String[] args)
- - - -
System.TypeLoadException: Method 'WriteJson' in type 'JsonToJsonConverter' from
assembly 'Raven.Http, Version=1.0.0.0, Culture=neutral, PublicKeyToken=37f41c7f9
9471593' does not have an implementation.
C:\RavenDB\Server>
I'm a total nub when it comes to this software.
Any ideas ?
Thanks
It seems to be an issue with version 206 I've gone back to 193 and it works fine.

NHibernate.MappingException - Trouble Shooting Checklist (no persister for)

Here's a starter list:
if hbm is hand generated, is it an embedded resource?
if using FNH, does it pass a PerssistenceSpecification test?
if not using FNH, can you save and then load the persisted class?
use Ayende's "sanity checks"
I'm sure many of you have gotten this one at one point or another. But have you ever gotten it when you knew your mapping was set up correctly?
I started getting this exception after I started using a new repository design, but only in one scenario! PersistenceSpecification tests pass, as do all repository methods (using SQLite).
The scenario that leads to the exception is when legacy projects from a different db are converted to green field system. The legacy system is from a different database and has it's own session factory, which should be irrelevant because the error comes after previously unconverted Projects are retrieved and in memory.
As the routine tries to save these unconverted Projects into the new database, the exception is thrown, full stack trace below.
Any ideas on how to build up the trouble shooting check list and solves this problem?
Cheers,
Berryl
=== the Exception trace =====
failed: NHibernate.MappingException : No persister for: Smack.ConstructionAdmin.Domain.Model.Projects.Project
at NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(String entityName)
at NHibernate.Impl.SessionImpl.GetEntityPersister(String entityName, Object obj)
at NHibernate.Engine.ForeignKeys.IsTransient(String entityName, Object entity, Nullable`1 assumed, ISessionImplementor session)
at NHibernate.Event.Default.AbstractSaveEventListener.GetEntityState(Object entity, String entityName, EntityEntry entry, ISessionImplementor source)
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event)
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event)
at NHibernate.Impl.SessionImpl.FireSaveOrUpdate(SaveOrUpdateEvent event)
at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj)
NHibernate\Repository\FabioNHibRepository.cs(46,0): at Smack.Core.Data.NHibernate.Repository.FabioNHibRepository`1.Add(T item)
LegacyConversion\LegacyBatchUpdater.cs(20,0): at Smack.ConstructionAdmin.Data.LegacyConversion.LegacyBatchUpdater.ConvertOpenLegacyProjects(ILegacyProjectDao legacyProjectDao, IProjectRepository greenProjectRepository)
Data\Brownfield\ProjectBatchUpdate_SQLiteTests.cs(19,0): at Smack.ConstructionAdmin.Tests.Data.Brownfield.ProjectBatchUpdate_SQLiteTests.Test()
The problem here turned out to be that I was inadvertently binding the same session context to both the legacy and greenfield db session factories, first to the greenfield and then the legacy.