The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,512 other followers

Exceptions handling in the EnterpriseLibrary and the “SecurityException: The source was not found, …”

Posted by jpluimers on 2013/09/03

A while ago, I inherited a .NET project that used the EnterpriseLibrary, the original developers (it got developed around 2003) were gone, and every exception would end up in this:

SecurityException: The source was not found, but some or all event logs could not be searched.  To create the source, you need permission to read all event logs to make sure that the new source name is unique.  Inaccessible logs: Security.

Searching for the combination “EnterpriseLibrary” “The source was not found, but some or all event logs could not be searched. To create the source, you need permission to read all event logs to make sure that the new source name is unique. Inaccessible logs: Security.” revealed only 1 result:

patterns & practices – Enterprise Library – View Discussion: Logging Error of FormattedEventLogTraceListener in Win7.

Even though I didn’t want anything to be logged in the EventLog, I wanted text logs, and looking at the .config files in the main project, the Enterprise Library logging setup was correct (right sinks, etc).

Somehow, the EnterpriseLibrary still insisted on writing to the eventlog, and this particular exception was the only one tricking to the unhandled exception layer…

For logging in the Eventlog, that particular event log must exist. In order to create an eventlog, you need to have administrator access. And here is the crux: apparantly, the original developers were (while working on Windows NT 4) all Administrators. So they never noticed this problem (and maybe never even looked for that log). After having the Visual Studio debugger break on all CLR exceptions, not only the unhandled ones, I could see this one shown below fired deep inside the EnterpriseLibrary. Which means that the original developers:

  1. did add the EnterpriseLibrary V2 (yes, this project still had V2 and part of the config files were V1.1!) configuration files to the main project:
  2. Had forgotten to mark these files as “Copy to Output Directory” to have the value “Copy if Newer” or “Copy Always”

Marking the files as such solved the below exception, and now on my todo list is to make the old V1.1 stuff go away, and migrate to the most current Enterprise Library.

System.Configuration.ConfigurationException was caught
  Message=Can not find the configuration file C:\...\bin\Debug\loggingConfiguration.config. You must check the 'path' attribute in the section 'loggingConfiguration'
  Source=Microsoft.Practices.EnterpriseLibrary.Configuration
  BareMessage=Can not find the configuration file C:\...\bin\Debug\loggingConfiguration.config. You must check the 'path' attribute in the section 'loggingConfiguration'
  Line=0
  StackTrace:
       at Microsoft.Practices.EnterpriseLibrary.Configuration.Storage.XmlFileStorageProvider.SetApplicationDocumentPathSetting(XmlFileStorageProviderData storageProviderData)
       at Microsoft.Practices.EnterpriseLibrary.Configuration.Storage.XmlFileStorageProvider.Initialize(ConfigurationView configurationView)
       at Microsoft.Practices.EnterpriseLibrary.Configuration.ProviderFactory.InitializeConfigurationProvider(String providerName, IConfigurationProvider provider)
       at Microsoft.Practices.EnterpriseLibrary.Configuration.StorageProviderFactory.InitializeConfigurationProvider(String sectionName, IConfigurationProvider provider)
       at Microsoft.Practices.EnterpriseLibrary.Configuration.ProviderFactory.InitializeObject(String providerName, Object createdObject)
       at Microsoft.Practices.EnterpriseLibrary.Configuration.ProviderFactory.CreateObject(String providerName, Type type)
       at Microsoft.Practices.EnterpriseLibrary.Configuration.ConfigurationFactory.CreateInstance(String configurationName)
       at Microsoft.Practices.EnterpriseLibrary.Configuration.StorageProviderFactory.Create(String sectionName)
       at Microsoft.Practices.EnterpriseLibrary.Configuration.ConfigurationBuilder.CreateStorageProvider(String sectionName)
       at Microsoft.Practices.EnterpriseLibrary.Configuration.ConfigurationBuilder.ReadConfiguration(String sectionName)
       at Microsoft.Practices.EnterpriseLibrary.Configuration.ConfigurationContext.GetConfiguration(String sectionName)
       at Microsoft.Practices.EnterpriseLibrary.Logging.LoggingConfigurationView.GetLoggingSettings()
       at Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter.Write(LogEntry log)
       at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler.WriteToLog(String logMessage)
       at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler.HandleException(Exception exception, String policyName, Guid handlingInstanceId)
       at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry.ExecuteHandlerChain(Exception ex, Guid handlingInstanceID)

–jeroen

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: