Note that there are some explanatory texts on larger screens.

plurals
  1. POCan Unity be made to not throw SynchronizationLockException all the time?
    text
    copied!<p>The Unity dependency injection container has what seems to be a widely known issue where the SynchronizedLifetimeManager will often cause the Monitor.Exit method to throw a SynchronizationLockException which is then caught and ignored. This is a problem for me because I like to debug with Visual Studio set to break on any thrown exception, so every time my application starts up I'm breaking on this exception multiple times for no reason.</p> <p><strong>How can I prevent this exception from being thrown?</strong></p> <p>Wherever this issues is mentioned elsewhere on the web, the advice usually involves changing the debugger settings to ignore it. This is akin to going to the doctor and saying, "Doctor, Doctor, my arm hurts when I raise it," to be told, "Well, stop raising it." I'm looking for a solution that stops the exception being thrown in the first place.</p> <p>The exception occurs in the SetValue method because it makes the assumption that GetValue will have been called first, where Monitor.Enter is called. However, the LifetimeStrategy and UnityDefaultBehaviorExtension classes both regularly call SetValue without calling GetValue.</p> <p>I'd rather not have to change the source code and maintain my own version of Unity, so I'm hoping for a solution where I can add some combination of extensions, policies, or strategies to the container that will ensure that, if the lifetime manager is a SynchronizedLifetimeManager, GetValue is always called before anything else.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload