Hi,
I'm getting the following exception from structure map - "Duplicate
Objects detected for Instance d54e25dc-d19c-4d70-99d1-56bd2502d203 of Type
..."
The stack trace is:
at StructureMap.InstanceCache.Set(Type pluginType, Instance Instance,
Object result) in
c:\code\structuremap\Source\StructureMap\InstanceCache.cs:line 60
at StructureMap.BuildSession.CreateInstance(Type pluginType, Instance
instance) in c:\code\structuremap\Source\StructureMap\BuildSession.cs:line
159
at StructureMap.BuildSession.<>c_DisplayClass3.<.ctor>b_1() in
c:\code\structuremap\Source\StructureMap\BuildSession.cs:line 34
at StructureMap.BuildSession.CreateInstance(Type pluginType) in
c:\code\structuremap\Source\StructureMap\BuildSession.cs:line 192
at StructureMap.BuildSession.GetInstance[T]() in
c:\code\structuremap\Source\StructureMap\BuildSession.cs:line 78
This exception happens only from time to time and is very difficult to
reproduce.
What I've found out so far:
Calling ObjectFactory.Container.GetInstance(type) will create a new
BuildSession with a new non-static cache.
The call will reach BuildSession.CreateInstance(Type pluginType, Instance
instance) and no instance is in the cache yet. (
https://github.com/structuremap/structuremap/blob/master/Source/Struc...
147)
Now we'll go on to _builder.Resolve(pluginType, instance, this);
Somewhere during Resolve() the object will get into the cache and later
in CreateInstance we're saving it into the cache once again, receiving the
exception.
That object is configured with Singleton lifecycle. The application is WCF
service hosted in IIS.
I still cannot understand why sometimes that object gets into the cache
twice.
I'd like to ask for all the possible ways how this can happen in SM.
Thank you.