SynchronizationLockException in ConfigureContainer

Topics: Prism v4 - WPF 4
Jul 21, 2011 at 12:22 AM

I have a UnityBootstrapper derived bootstrapper class, with an overridden ConfigureContainer function. When calling this.Container.RegisterInstance or this.Container.RegisterType, I get the following exception message:

A first chance exception of type 'System.Threading.SynchronizationLockException' occurred in Microsoft.Practices.Unity.dll

Additional information: Object synchronization method was called from an unsynchronized block of code.

Any ideas on why this might be happening and how I might go about fixing it?

Jul 21, 2011 at 4:43 PM


We've tried overriding that method and we've experienced no errors. The exception you're experiencing might be happening due to the fact that some code that involves synchronization locks might be placed in your class's constructor, and when you use the RegisterType method, that code is being called, thus throwing the exception.

If you can't find a cause for your problem, it would be helpful if you could provide us with a repro sample (for example, uploading it to SkyDrive), so that we can help you solve this issue.

I hope you find this helpful.

Guido Leandro Maliandi

Dec 18, 2011 at 12:20 AM
Edited Dec 18, 2011 at 12:24 AM




The same...

It's too late, but if I have understood correctly, I have the problem in myBootstrapperGestionAplicacion
Is it right?

The million dollar question. Is this important? How concerned?
thank you very much

    public partial class App : Application
        protected override void OnStartup(StartupEventArgs e)
            BootstrapperGestionAplicacion b = new BootstrapperGestionAplicacion();
Dec 19, 2011 at 3:53 PM


Based on my understanding, the problem described in this thread, as Guido Maliandi suggested, might be located in the constructor of the class you are trying to register when overriding the ConfigureContainer method, possibly due to some code that involves synchronization locks in it.

Regarding the code snippet you provided, it seems to be a valid approach to initialize your bootstrapper and doesn't seems to be related to the problem.

If you are still experiencing this undesired behavior it would be helpful if you could provide us with a repro sample application, so that we can help you further with this.

Agustin Adami

Feb 19, 2012 at 4:24 PM


I think this is related to a known issue in Unity [running the Modularity with Unity quickstart in debug repros the issue]


A 'handled' exception arises in SynchronizedLifetimeManager.cs:

        private void TryExit()
            catch (SynchronizationLockException)
                // Noop here - we don't hold the lock and that's ok.

which is called by SetValue.

Monitor.Enter(lockobj) is called by GetValue, but SetValue can be called without a previous call to GetValue with the result that a SynchronizationLockException is generated.

There are some workarounds possible for users of Unity outside of Prism on [see].