As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/
Options

Enterprise Library and Exceptions

JeiceJeice regular
edited February 2009 in Help / Advice Forum
I'm trying to use Enterprise Library to handle all my exceptions, and I've followed the tutorials on the internet, but I keep getting the same error. So, after 2 days of googling and looking for ways to fix the error, I come to you guys for ideas/solutions.

This is the code I'm trying to run:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
using System.Collections.Specialized;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration;

decimal num = 9;
decimal den = 0;

try
{
decimal result = num / den;
}

catch (DivideByZeroException exception)
{
bool rethrow = ExceptionPolicy.HandleException(exception, "Exception Policy"); // this is where the error is happening
if (rethrow)
{
throw;
}
}

This is the xml that I generated using Enterprise Library Configuration and following the tutorials:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<section name="enterpriselibrary.configurationSettings" type="EnterpriseLibraryHelper.ConfigurationManagerSectionHandler, EnterpriseLibraryHelper, Version=1.0, Culture=neutral, PublicKeyToken=null" />
</configSections>
<exceptionHandling>
<exceptionPolicies>
<add name="Exception Policy">
<exceptionTypes>
<add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="NotifyRethrow" name="Exception" />
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>
<enterpriselibrary.configurationSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema&quot; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot; applicationName="Application" xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/configuration"&gt;
<configurationSections>
<configurationSection xsi:type="ReadOnlyConfigurationSectionData" name="loggingConfiguration" encrypt="false">
<storageProvider xsi:type="XmlFileStorageProviderData" name="XML File Storage Provider" path="loggingConfiguration.config" />
<dataTransformer xsi:type="CustomTransformerData" name="Xml Serializer Transformer turbo" type="EnterpriseLibraryHelper.XmlSerializerTransformer, EnterpriseLibraryHelper, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<Attributes name="serializerType" value="EnterpriseLibraryHelper.LoggingSettingsSerializer.XmlSerializationWriter1, EnterpriseLibraryHelper, Version=1.0, Culture=neutral, PublicKeyToken=null" />
<Attributes name="deserializerType" value="EnterpriseLibraryHelper.LoggingSettingsSerializer.XmlSerializationReader1, EnterpriseLibraryHelper, Version=1.0, Culture=neutral, PublicKeyToken=null" />
</dataTransformer>
</configurationSection>
<configurationSection xsi:type="ReadOnlyConfigurationSectionData" name="loggingDistributorConfiguration" encrypt="false">
<storageProvider xsi:type="XmlFileStorageProviderData" name="XML File Storage Provider" path="loggingDistributorConfiguration.config" />
<dataTransformer xsi:type="CustomTransformerData" name="Xml Serializer Transformer turbo" type="EnterpriseLibraryHelper.XmlSerializerTransformer, EnterpriseLibraryHelper, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<Attributes name="serializerType" value="EnterpriseLibraryHelper.DistributorSettingsSerializer.XmlSerializationWriter1, EnterpriseLibraryHelper, Version=1.0, Culture=neutral, PublicKeyToken=null" />
<Attributes name="deserializerType" value="EnterpriseLibraryHelper.DistributorSettingsSerializer.XmlSerializationReader1, EnterpriseLibraryHelper, Version=1.0, Culture=neutral, PublicKeyToken=null" />
</dataTransformer>
</configurationSection>
</configurationSections>
<keyAlgorithmStorageProvider xsi:nil="true" />
<includeTypes />
<exceptionHandling>
<exceptionHandlingConfiguration>
<xmlSerializerSection type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=1.1.0.0, Culture=neutral, PublicKeyToken=66c36a3abdf5268d">
<enterpriseLibrary.exceptionHandlingSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema&quot; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot; xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/exceptionhandling"&gt;
<exceptionPolicies>
<exceptionPolicy name="Exception Policy">
<exceptionTypes>
<exceptionType name="Exception" type="System.Exception, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="NotifyRethrow">
<exceptionHandlers>
<exceptionHandler xsi:type="LoggingExceptionHandlerData" name="Logging Handler" defaultLogCategory="Trace" defaultEventID="100" defaultSeverity="Error" defaultTitle="Enterprise Library Exception Handling" formatterTypeName="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=1.1.0.0, Culture=neutral, PublicKeyToken=66c36a3abdf5268d" minimumPriority="0" />
</exceptionHandlers>
</exceptionType>
</exceptionTypes>
</exceptionPolicy>
</exceptionPolicies>
</enterpriseLibrary.exceptionHandlingSettings>
</xmlSerializerSection>
</exceptionHandlingConfiguration>
<exceptionPolicies>
<add name="ExternalPolicy">
<exceptionTypes>
<add name="Exception" type="System.Exception, mscorlib" postHandlingAction="ThrowNewException">
<exceptionHandlers>
<add name="WrapHandler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WrapHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" exceptionMessage="Test Message" wrapExceptionType="System.ApplicationException, mscorlib" />
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>
</enterpriselibrary.configurationSettings>
</configuration>

This is the error message I keep getting:
Invalid section name. The section 'exceptionHandlingConfiguration' does not exist in the requested configuration file 'C:\...\web.config' or the file 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\machine.config'. Make sure that the 'enterpriseLibrary.configurationSections' configuration section exists in one of the files and that the section 'exceptionHandlingConfiguration' is defined.

I am using C# in Microsoft Visual Studio to run this.

Jeice on

Posts

  • Options
    JHunzJHunz Registered User regular
    edited February 2009
    I am no expert on C# or this library.
    However, the section name in your configuration file is "enterpriselibrary.configurationSettings" and the one that the error message indicates should exist is "enterpriseLibrary.configurationSections".

    JHunz on
    bunny.gif Gamertag: JHunz. R.I.P. Mygamercard.net bunny.gif
Sign In or Register to comment.