1

Closed

Unity exception when user defined service endpoint called concurrently

description

Hi, I got the following exception where an endpoint I defined was being called simultaneously, I created a unit test to spin up to 10 threads (I am using XP) with each thread making an httppost to the endpoint at roughly the same time. The 500 error and following exception were easily re-creatable this way:
 
[InvalidOperationException: The current type, MockingBird.Simulator.Framework.Interfaces.IExecutionContext, is an interface and cannot be constructed. Are you missing a type mapping?]
Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.ThrowForAttemptingToConstructInterface(IBuilderContext context) +214
BuildUp_MockingBird.Simulator.Framework.Interfaces.IExecutionContext(IBuilderContext ) +113
Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) +12
Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +191
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +97
 
[BuildFailedException: The current build operation (build key Build Key[MockingBird.Simulator.Framework.Interfaces.IExecutionContext, null]) failed: The current type, MockingBird.Simulator.Framework.Interfaces.IExecutionContext, is an interface and cannot be constructed. Are you missing a type mapping? (Strategy type BuildPlanStrategy, index 3)]
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +275
Microsoft.Practices.ObjectBuilder2.Builder.BuildUp(IReadWriteLocator locator, ILifetimeContainer lifetime, IPolicyList policies, IStrategyChain strategies, Object buildKey, Object existing) +59
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name) +152
 
[ResolutionFailedException: Resolution of the dependency failed, type = "MockingBird.Simulator.Framework.Interfaces.IExecutionContext", name = "". Exception message is: The current build operation (build key Build Key[MockingBird.Simulator.Framework.Interfaces.IExecutionContext, null]) failed: The current type, MockingBird.Simulator.Framework.Interfaces.IExecutionContext, is an interface and cannot be constructed. Are you missing a type mapping? (Strategy type BuildPlanStrategy, index 3)]
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name) +190
Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name) +11
Microsoft.Practices.Unity.UnityContainerBase.Resolve() +65
MockingBird.Simulator.Interceptors.Classic.ClassicInterceptor.ProcessRequest(HttpContext httpContext) in C:\3_EVO\COMPONENTS\HRG.BE\Test\mockingbird\main\source\Simulator\Interceptors\Classic\ClassicInterceptor.cs:56
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
 
This error was not limited to any one line of code, but to any line for resolving type for interface, I noticed that as soon as one call failed, all subsequent calls would fail. I could not recreate this outside of IIS, by isolating the dependency resolution in a unit test for example.
 
This error is commonly seen (as I understand it) where the unity config is not correct, I've also seen this where the unity libs were not found...
 
I was able to fix this on my machine (XP) and (which also works when deployed to a Server 2003 dev box) by altering the source code so that the unity container is accessed from the http context rather than a static variable (which I believe is otherwise pinned to the app domain).
 
I suspect the issue is to do access to the unity instance by multiple IIS threads, I presume that accessing the unity container via the http context put's control of this resource into IIS - the context must be managed efficiently within IIS. I also believe I've noticed a significant performance increase by doing this, but have not spent time to formally assess this.
 
I do not know if you have seen this issue before. I downloaded the source fairly recently - mockingbird-32264.zip
 
Cheers,
b
Closed Mar 29, 2010 at 10:25 AM by santoshbenjamin
This has been fixed in v2.0 RC

comments

santoshbenjamin wrote Feb 22, 2010 at 10:11 PM

Hi, Yes, we noticed this when building the WCF version and running concurrency tests on it using MS Chess. The 2.0 release due out this following weekend (28 feb approx) should have the issue fixed.

cheers,
benjy

wrote Mar 29, 2010 at 10:25 AM

wrote Feb 14, 2013 at 12:19 AM

wrote May 16, 2013 at 7:24 AM