Exception: An item with the same key has already been added

Topics: Exception Handling Application Block, Logging Application Block
Sep 3, 2008 at 7:54 AM
I get this exception after second invoke ExceptionPolicy.HandleException(ex, ExceptionPolicyName);

The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl, CommonPolicy]) failed: The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter, null]) failed: An item with the same key has already been added. (Strategy type Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy, index 2) (Strategy type Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy, index 2)

   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.GetExceptionPolicy(Exception exception, String policyName, ExceptionPolicyFactory factory)
   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName, ExceptionPolicyFactory policyFactory)
   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName)
   at MyProj.TaskSchedulerService.TaskSchedulerService.ProcessCryptoInfoCleaning(Object state) in D:\Projects\Work\MyProj\Sources\MyProj\MyProj.TaskSchedulerService\TaskSchedulerService.cs:line 159
   at System.Threading._TimerCallback.TimerCallback_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading._TimerCallback.PerformTimerCallback(Object state)

<configSections>

 

<

section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

 

<

section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

 

<

section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

 

</

configSections>

 

<

loggingConfiguration name="Logging Application Block" tracingEnabled="true"

 

 

 

 

 

defaultCategory="" logWarningsWhenNoCategoriesMatch="true">

 

<

listeners>

 

<

add fileName="Log\TaskScheduler.log" footer="----------------------------------------"

 

 

 

 

 

formatter="Text Formatter" header="----------------------------------------"

 

 

 

 

 

rollFileExistsBehavior="Overwrite" rollInterval="Day" rollSizeKB="0"

 

 

 

 

 

timeStampPattern="yyyy-MM-dd" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

 

 

 

traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

 

 

 

name="Rolling Flat File Trace Listener" />

 

</

listeners>

 

<

formatters>

 

<

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, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

 

 

 

name="Text Formatter" />

 

</

formatters>

 

<

categorySources>

 

<

add switchValue="All" name="Errors">

 

<

listeners>

 

<

add name="Rolling Flat File Trace Listener" />

 

</

listeners>

 

</

add>

 

</

categorySources>

 

<

specialSources>

 

<

allEvents switchValue="All" name="All Events" />

 

<

notProcessed switchValue="All" name="Unprocessed Category" />

 

<

errors switchValue="All" name="Logging Errors &amp; Warnings">

 

<

listeners>

 

<

add name="Rolling Flat File Trace Listener" />

 

</

listeners>

 

</

errors>

 

</

specialSources>

 

</

loggingConfiguration>

 

<

exceptionHandling>

 

<

exceptionPolicies>

 

<

add name="CommonPolicy">

 

<

exceptionTypes>

 

<

add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

 

 

 

 

 

postHandlingAction="NotifyRethrow" name="Exception">

 

<

exceptionHandlers>

 

<

add logCategory="Errors" eventId="100" severity="Error" title="MyProj.TaskScheduler Exception Handling"

 

 

 

 

 

formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

 

 

 

priority="0" useDefaultLogger="false" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

 

 

 

name="Logging Handler" />

 

</

exceptionHandlers>

 

</

add>

 

</

exceptionTypes>

 

</

add>

 

</

exceptionPolicies>

 

</

exceptionHandling>

 

Sep 3, 2008 at 12:44 PM
Hi,

This is a known issue http://www.codeplex.com/entlib/WorkItem/View.aspx?WorkItemId=17534; it will be fixed in v4.1.

Regards,
Fernando