What am I doing wrong here or what am I not doing? (I am using this code in a .NET 4.0 WCF Service)
private static ICacheManager GetCacheManager()
{
try
{
return CacheFactory.GetCacheManager();
}
catch (SynchronizationLockException ex)
{
EventLogHelper.WriteError(ex);
}
catch (ConfigurationException ex)
{
EventLogHelper.WriteError(ex);
}
return null;
}
When debugger hits return it throws this exception:
System.Threading.SynchronizationLockException occurred Message=Object synchronization method was called from an unsynchronized block of code. Source=Microsoft.Practices.Unity StackTrace: at Microsoft.Practices.Unity.SynchronizedLifetimeManager.TryExit() in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\Lifetime\SynchronizedLifetimeManager.cs:line 109 InnerException:
Is this a bug in Enterprice library?
The problem exists in many Enterprise Library blocks indeed. It has something to do with the way Unity is implemented. The actual problem is not that the code itself is incorrect. The exception is catched, but the debugger seems to ignore that fact.
The problem is described here:
Unfortunately, there is not much you can do to avoid this bug. It would definitely be nice if the Patterns & Practices team should be more iterative in solving this problem ;) .
Happy coding!
It seems that the exception is thrown internally by the Enterprise Library Unity block, however it is also handled as well. This had me pulling my hear out until I realised I had Break when an exception is Thrown enabled for CLR Exception.
Debug -> Exception
Unticking this stopped the debugger from breaking when the exception is thrown.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With