I have found the Microsoft Application Blocks for .NET very helpful and reusable. However, today I had fun chasing my tail trying to deploy the Microsoft Exception Management Application Block (EMAB). I kept getting this exception in my exception handler:

System.Security.SecurityException: Requested registry access is not allowed.
[SecurityException: Requested registry access is not allowed.]
Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable) +440
System.Diagnostics.EventLog.CreateEventSource(String source, String logName, String machineName, Boolean useMutex)
System.Diagnostics.EventLog.CreateEventSource(String source, String logName, String machineName)
System.Diagnostics.EventLog.CreateEventSource(String source, String logName)
Microsoft.ApplicationBlocks.ExceptionManagement.DefaultPublisher.VerifyValidSource()

This exception made me scratch my head since I am not writing any exceptions to the registry. I kept trying to tweak my Web.Config file which contains all my application settings. I assumed that since the error message contained “DefaultPublisher” that my “CustomPublisher” was not executing. Therefore, I keep playing with its configuration trying to make it run.

I didn’t get far doing this and I decided to check the directory permissions where my exception logging was being serialized. I forgot to setup directory level security for this folder on the remote web server. What frustrates me is this security exception wrongly reported that
a) the “DefaultPublisher” was executing when it wasn’t
b) the security exception was in the registry when it was in the file system

I played around a little and confirmed every security exception generates this same message. Wonderful, this security exception must be hard coded for all security problems.