Problem with ConfigurationSourceFactory and customconfigurationsections

Topics: Exception Handling Application Block, Logging Application Block
Jul 16, 2008 at 3:59 PM
Edited Jul 16, 2008 at 4:15 PM
Hello,
i have a web application that uses different configsections in the web.config file. I have in different files the Exception Handling, Logging policies and 2 custom configuration sections i use to read data depending the day of the week.
Problem is that when i try to create a Tracer to write info in any log, i get an error message saying:
"The configuration could not be found for name 'CustomConfiguration' in factory ConfigurationSourceFactory."

CustomConfiguration is one of my custom sections. Thing is this is a migrated application from EntLib 1.1 to 3.1 and dont know what could be causing the problem.
I have tried to look for the error message and reading the documentation but i still dont get it.

Could you please help me with this? I could paste here the logging and exceptionhandling secionts but i dont feel like it cause they are a bit extensive. If u want to see any code just tell me and i will paste it here.
Im desperate.

EDIT: Basically the tracer ends in ConfigurationSectionFactory.cs in this code

<summary>

 

/// Creates a new configuration sources based on the default configuration information from the

 

/// application's default configuration file.

 

/// </summary>

 

/// <returns>The new configuration source instance described as the default in the configuration file,

 

/// or a new instance of <see cref="SystemConfigurationSource"/> if the is no configuration sources configuration.</returns>

 

/// <exception cref="ConfigurationSourceSection">when there is a configuration section but it does not define

 

/// a default configurtion source, or when the configuration for the defined default configuration source is not found.</exception>

 

public static IConfigurationSource Create()

{

ConfigurationSourceSection configurationSourceSection

= ConfigurationSourceSection.GetConfigurationSourceSection();  <----- This is return my CustomConfiguration Section

 

if (configurationSourceSection != null)

{

 

string systemSourceName = configurationSourceSection.SelectedSource;

 

if (!string.IsNullOrEmpty(systemSourceName))

{

 

return Create(systemSourceName); <---- Here is when it does not find the CustomConfiguration name and raises the exception

}

 

else

 

{

throw new ConfigurationErrorsException(Resources.ExceptionSystemSourceNotDefined);

}

}

 

return new SystemConfigurationSource();

 

I have seen this thread too that has some similarities with my problem (Other Thread) . Just to say i have no problems with my .config file since its read by the application and recognizes my CustomConfiguration Section

Jul 16, 2008 at 6:18 PM
Hi,

I'm a bit confused here. You mention you have a custom configuration section, but the code you show is about creating configuration sources. The exception you get means that there is no configuration source for the name you requested in your configuration sources configuration section.

Can you clarify your situation?

Fernando
Jul 16, 2008 at 6:44 PM
Yes, i cannot post here the code at the moment since its the laptop and im travelling.

Basically i read from my custom configuration the path to a folder where i store some xml files.
Then when im reading and loading into memory some xml files from there i use a tracer to log the phrase "Loading " + file.filename + " configuration file".

The tracer inherits from an EntLib class, and when it goes to write in the logs, he uses the configurationsourcefactory, thats the code above. Thing is i dont know know why it calls the configurationsourcefactory to write.

I think i need something else to configure the trace class. I doubt this is enough information, but is what i can post atm later i will write more.
Jul 16, 2008 at 7:08 PM
Hi,

You mention that you ported your app from v1.1. Configuration changed dramatically in v2.0 to align EntLib with the new configuration features provided by the .NET framework, so many concepts from v1.1 do not have a direct equivalent in v2.0 and later.

I suggest you take a look a the new versions of the Logging QuickStart, which shows how configuration works now.

Regards,
Fernando



Aryslan wrote:
Yes, i cannot post here the code at the moment since its the laptop and im travelling.

Basically i read from my custom configuration the path to a folder where i store some xml files.
Then when im reading and loading into memory some xml files from there i use a tracer to log the phrase "Loading " + file.filename + " configuration file".

The tracer inherits from an EntLib class, and when it goes to write in the logs, he uses the configurationsourcefactory, thats the code above. Thing is i dont know know why it calls the configurationsourcefactory to write.

I think i need something else to configure the trace class. I doubt this is enough information, but is what i can post atm later i will write more.



Jul 17, 2008 at 8:57 AM
Edited Jul 17, 2008 at 10:11 AM
I think i got the root of the problem.
Basically the web.config had a left over tha the Entlib Configuration tool:
<configSections>
    <section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </configSections>
  <enterpriseLibrary.ConfigurationSource selectedSource="CustomConfiguration">
    <sources>
      <add name="CustomConfiguration" type="MyApp.Common.Configuration.CommonApplicationConfiguration, MyApp.Common"
        filePath="Configuration\externalconfig" />
      <add name="exceptionHandlingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
        filePath="Configuration\ExceptionHandlingConfiguration.config" />
      <add name="loggingDistributorConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
        filePath="Configuration\LoggingDistributorConfiguration.config" />
    </sources>
  </enterpriseLibrary.ConfigurationSource>
.....

So i changed the web.config to look like the following

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="CommonApplicationConfiguration" type="MyApp.Common.Configuration.CommonApplicationConfiguration, MyApp.Common" />
    <section name="exceptionHandlingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" />
    <section name="loggingDistributorConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging" />
  </configSections>
  <system.web>
    <httpHandlers>
      <add verb="*" path="Route.aspx" type="MyApp.Common.Web.HttpHandlers.RoutingHandler, MyApp.Common" />
      <add verb="*" path="Route.ica" type="MyApp.Common.Web.HttpHandlers.RoutingHandler, MyApp.Common" />
      <add verb="*" path="RouteDebug.aspx" type="MyApp.Common.Web.HttpHandlers.DebugRoutingHandler, MyApp.Common" />
    </httpHandlers>
    ......
</configuration>


With this web.config, when i use a "new Tracer("Raising Exception");" it gives me the following error: The configuration section for Logging cannot be found in the configuration source.
So i modified the web.config to look like this again:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="CommonApplicationConfiguration" type="MyApp.Common.Configuration.CommonApplicationConfiguration, MyApp.Common" />
    <section name="exceptionHandlingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" />
    <section name="Logging " type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging" />
  </configSections>
  <system.web>
    <httpHandlers>
      <add verb="*" path="Route.aspx" type="MyApp.Common.Web.HttpHandlers.RoutingHandler, MyApp.Common" />
      <add verb="*" path="Route.ica" type="MyApp.Common.Web.HttpHandlers.RoutingHandler, MyApp.Common" />
      <add verb="*" path="RouteDebug.aspx" type="MyApp.Common.Web.HttpHandlers.DebugRoutingHandler, MyApp.Common" />
    </httpHandlers>
    ......
</configuration>

Thing is the same error keeps happening. I was looking the Quick Logging guide of the EntLib 2.0 and i realized this was the problem but still i cannot find a workaround to this. Any suggestions?
Jul 17, 2008 at 10:18 AM
If i do a System.Configuration.ConfigurationManager.GetSection("Logging") it returns me the section with the recognized trace listeners, formatters, etc...

This is my Logging file:

  <Logging name="Logging Application Block" tracingEnabled="true"
    defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
    <logFilters>
      <add
                name="Category"
                type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.CategoryFilter, Microsoft.Practices.EnterpriseLibrary.Logging"
                categoryFilterMode="AllowAllExceptDenied">
        <categoryFilters>
          <add name="UI Events" />
        </categoryFilters>
      </add>
      <add
                name="Priority"
                type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.PriorityFilter, Microsoft.Practices.EnterpriseLibrary.Logging"
                minimumPriority="0"
                    />
      <add name="LogEnabled Filter"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging"
        enabled="true"
           />
    </logFilters>
    <listeners>
      <add listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
        traceOutputOptions="None"
        type="MyApp.Common.Logging.ConsoleSink, MyApp.Common"
        name="Console Sink"
        initializeData=""
        formatter="Console Message Formatter" />
      <add fileName="trace.log"
        header="----------------------------------------"
        footer="----------------------------------------"
        formatter=""
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
        traceOutputOptions="None"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
        name="Flat File Sink (trace.log)" />
      <add source="MyApp Logging"
        formatter="Console Message Formatter"
        log="Application"
        machineName="."
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
        traceOutputOptions="None"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
        name="Application EventLog Sink" />
      <add listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
        traceOutputOptions="None"
        type="MyApp.Common.Logging.ConsoleSink, MyApp.Common"
        name="Console Sink(text)"
        initializeData=""
        formatter="Text Formatter" />
      <add listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
        traceOutputOptions="None"
        type="MyApp.Common.Logging.ConsoleSink, MyApp.Common"
        name="Console Sink(trace)"
        initializeData=""
        formatter="Trace Formatter" />
      <add source="MyApp Logging"
        formatter="Text Formatter"
        log="MyApp"
        machineName=""
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
        traceOutputOptions="None"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
        name="MyApp EventLog Sink" />
      <add source="MyApp Logging"
        formatter="Trace Formatter"
        log="MyApp"
        machineName="."
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
        traceOutputOptions="None"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
        name="MyApp EventLog Sink(trace)" />
    </listeners>
    <formatters>
      <add template="{message}&#xD;&#xA;)}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging"
        name="Console Message Formatter" />
      <add template="Timestamp: {timestamp}&#xD;&#xA;Message  : {message}&#xD;&#xA;ExtProp  : {dictionary({key} - {value})}&#xD;&#xA;)}"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging"
        name="Short Formatter" />
      <add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties:{dictionary(  - {key}: {value})}&#xD;&#xA;)}"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging"
        name="Text Formatter" />
      <add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;&#xD;&#xA;Extended Properties:&#xD;&#xA;&#xD;&#xA;{dictionary({key} - {value}{newline})}&#xD;&#xA;)}"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging"
        name="Trace Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="XmlFileHandling">
        <listeners>
          <add name="Console Sink(text)" />
          <add name="MyApp EventLog Sink" />
        </listeners>
      </add>
      <add switchValue="All" name="Trace">
        <listeners>
          <add name="Console Sink(trace)" />
          <add name="MyApp EventLog Sink(trace)" />
        </listeners>
      </add>
      <add switchValue="All" name="TopLevel">
        <listeners>
          <add name="Console Sink" />
          <add name="MyApp EventLog Sink" />
        </listeners>
      </add>
      <add switchValue="All" name="ProductionTrace">
        <listeners>
          <add name="Console Sink(trace)" />
          <add name="MyApp EventLog Sink(trace)" />
        </listeners>
      </add>
      <add switchValue="All" name="ConsoleVerbose">
        <listeners>
          <add name="Console Sink" />
        </listeners>
      </add>
      <add switchValue="All" name="ConsoleDefault">
        <listeners>
          <add name="Console Sink" />
        </listeners>
      </add>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Console Sink(text)" />
          <add name="MyApp EventLog Sink" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events" />
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="All" name="Logging Errors &amp; Warnings" />
    </specialSources>
  </Logging>
Jul 17, 2008 at 11:44 AM
After more investigation i found that pasting the logging configuration from the example given in the logging quickstart i cannot make it to work.
I am tracing the code and the error comes when the Tracer class internally tries to create a LogWritter:
/// <summary>
        /// Creates a new instance of <see cref="LogWriter"/> based on the configuration in the <see cref="IConfigurationSource"/>
        /// instance of the factory.
        /// </summary>
        /// <returns></returns>
        public LogWriter Create()
        {
            return EnterpriseLibraryFactory.BuildUp<LogWriter>(configurationSource);
        }
Jul 17, 2008 at 12:36 PM
Found the solution. Problem was a bad compilated EntLib dll.
Basically after too much time wasted i created a new app just with the code NEW TRACER("BLA BLA BLA").
I put as references my signed EntLib and got the following error.
 {"Could not load file or assembly 'Microsoft.Practices.ObjectBuilder, Version=1.0.51206.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.":"Microsoft.Practices.ObjectBuilder, Version=1.0.51206.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"}

Meaning something inside EntLib dll was pointing to the 1.0 version of it. Replaced those references by the default dll supplied by EntLib and works perfectly. So im going to use the default ones and exchange them by the signed at the end.

Thanks for the help Fernando.
BTW are u spanish?
Jul 17, 2008 at 1:03 PM
Hi,

It's great that it works for you now. However, I could see you were using the "Logging" name for the Logging block's configuration section instead the "loggingConfiguration" name actually used by the block to look for configuration; did you fix that too?

No, I'm not spanish.

Regards,
Fernando


Aryslan wrote:
Found the solution. Problem was a bad compilated EntLib dll.
Basically after too much time wasted i created a new app just with the code NEW TRACER("BLA BLA BLA").
I put as references my signed EntLib and got the following error.
 {"Could not load file or assembly 'Microsoft.Practices.ObjectBuilder, Version=1.0.51206.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.":"Microsoft.Practices.ObjectBuilder, Version=1.0.51206.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"}

Meaning something inside EntLib dll was pointing to the 1.0 version of it. Replaced those references by the default dll supplied by EntLib and works perfectly. So im going to use the default ones and exchange them by the signed at the end.

Thanks for the help Fernando.
BTW are u spanish?



Jul 17, 2008 at 4:26 PM
Yea i fixed it too. Just after posting here. Thing is that dll  i mentioned is okay even being version 1.0.51206 since it appears that way in the EntLib, problem was bad signing with them. Already solved. Damn it took me a travel thru hell to realize this.