diff --git a/src/Spring/Spring.Core/Reflection/Dynamic/DynamicMethod.cs b/src/Spring/Spring.Core/Reflection/Dynamic/DynamicMethod.cs index 33e85267..6ae7f637 100644 --- a/src/Spring/Spring.Core/Reflection/Dynamic/DynamicMethod.cs +++ b/src/Spring/Spring.Core/Reflection/Dynamic/DynamicMethod.cs @@ -88,7 +88,7 @@ namespace Spring.Reflection.Dynamic private class IdentityTable : Hashtable { public IdentityTable() - {} + { } protected override int GetHash(object key) { @@ -118,14 +118,24 @@ namespace Spring.Reflection.Dynamic state = (SafeMethodState)stateCache[methodInfo]; if (state == null) { - state = new SafeMethodState(DynamicReflectionManager.CreateMethod(methodInfo), - new object[methodInfo.GetParameters().Length] + SafeMethodState newState = new SafeMethodState(DynamicReflectionManager.CreateMethod(methodInfo), + new object[methodInfo.GetParameters().Length] ); - stateCache[methodInfo] = state; + + lock (stateCache.SyncRoot) + { + if (stateCache[methodInfo] == null) + { + state = newState; + stateCache[methodInfo] = state; + } + } } + this.methodInfo = methodInfo; } + /// /// Invokes dynamic method. ///