Really basic Exception Handling problem (newbie of course!)

Topics: Exception Handling Application Block
Oct 2, 2010 at 5:40 PM
Edited Oct 2, 2010 at 9:27 PM

I'm trying to set up a really simple example of EntLib 5.0 exception handling.
i've looked at the hands on lab, developers guide and quite a few posts on this site.
i thought this post might help but it didn't:
http://entlib.codeplex.com/Thread/View.aspx?ThreadId=211771

here's the code i am running:
var exManager = EnterpriseLibraryContainer.Current.GetInstance<ExceptionManager>();

or even:

IUnityContainer c = new UnityContainer().AddNewExtension<EnterpriseLibraryCoreExtension>();

or even still:

            var container = new UnityContainer();
            var configurator = new UnityContainerConfigurator(container);
            EnterpriseLibraryContainer.ConfigureContainer(configurator, ConfigurationSourceFactory.Create());

either way, heres the exception i get:
System.ArgumentException was unhandled by user code
  Message="Type does not provide a constructor taking a single parameter type of NameValueCollection"
  Source="Microsoft.Practices.EnterpriseLibrary.Common"
  StackTrace:
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.RegistrationExpressionBuilder.BuildNewExpression(Type typeToBuild, NameValueCollection attributes) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\RegistrationExpressionBuilder.cs:line 59
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.RegistrationExpressionBuilder.BuildExpression(Type typeToBuild, NameValueCollection attributes) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\RegistrationExpressionBuilder.cs:line 37
       at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.CustomHandlerData.<GetRegistrations>d__1.MoveNext() in e:\Builds\EntLib\Latest\Source\Blocks\ExceptionHandling\Src\ExceptionHandling\Configuration\CustomHandlerData.cs:line 208
       at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
       at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
       at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection)
       at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings.GetRegistrations(IConfigurationSource configurationSource) in e:\Builds\EntLib\Latest\Source\Blocks\ExceptionHandling\Src\ExceptionHandling\Configuration\ExceptionHandlingSettings.cs:line 96
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ConfigSectionLocator.<GetRegistrations>b__0(ITypeRegistrationsProvider p, IConfigurationSource cs) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\ConfigSectionLocator.cs:line 60
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ConfigSectionLocator.GetRegistrationsInternal(IConfigurationSource configurationSource, Func`3 registrationsAccessor) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\ConfigSectionLocator.cs:line 88
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ConfigSectionLocator.GetRegistrations(IConfigurationSource configurationSource) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\ConfigSectionLocator.cs:line 60
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.CompositeTypeRegistrationsProviderLocator.<GetRegistrations>b__0(ITypeRegistrationsProvider l, IConfigurationSource cs) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\TypeRegistrationsProvider.cs:line 128
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.CompositeTypeRegistrationsProviderLocator.<>c__DisplayClass5.<GetRegistrationsInternal>b__4(ITypeRegistrationsProvider l) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\TypeRegistrationsProvider.cs:line 147
       at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.Unity.UnityContainerConfigurator.RegisterAllCore(IConfigurationSource configurationSource, ITypeRegistrationsProvider rootProvider) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\Unity\UnityContainerConfigurator.cs:line 61
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ChangeTrackingContainerConfigurator.RegisterAll(IConfigurationSource configurationSource, ITypeRegistrationsProvider rootProvider) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\ChangeTrackingContainerConfigurator.cs:line 66
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.ConfigureContainer(ITypeRegistrationsProvider locator, IContainerConfigurator configurator, IConfigurationSource configSource) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 83
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.ConfigureContainer(IContainerConfigurator configurator, IConfigurationSource configSource) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 62
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.CreateDefaultContainer(IConfigurationSource configurationSource) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 122
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.CreateDefaultContainer() in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 108
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.SetCurrentContainerIfNotSet() in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 95
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.get_Current() in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 36
       at webEL_EH._Default.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\Walt Elviserate\My Documents\Visual Studio 2008\Projects\personal\el\exception\webEL_EH\webEL_EH\Default.aspx.cs:line 30
       at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
       at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
       at System.Web.UI.Control.OnLoad(EventArgs e)
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException:
here's the relevant part of the webconfig (all this was set up by the config tool apart for the unity config section (not shown)):
  <exceptionHandling>
    <exceptionPolicies>
      <add name="MyPolicy">
        <exceptionTypes>
          <add name="AllExceptions" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="None">
            <exceptionHandlers>
              <add type="webEL_EH.Chandler, webEL_EH, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                name="Chandler" />
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
    </exceptionPolicies>
  </exceptionHandling>
  Please note that I'm trying to use a custom exception handler "Chandler" and that the config tool recognizes this as a valid handler.

what am i doing wrong?? i've read the dev documentation and every example appears to pass in an instance of the exception manager...i can't even get that far!

I'd also like to be able to do this via a config file too...

Please help!

thanks in advance.

Oct 4, 2010 at 1:10 AM

Your custom exception handler should have a constructor taking a parameter of type NameValueCollection.

public Chandler(NameValueCollection attributes) { }

 

Sarah Urmeneta
Global Technology and Solution
Avanade, Inc.
entlib.support@avanade.com

Oct 5, 2010 at 1:09 PM

thanks Sarah. that worked. I remember seeing that in the documentation too! the woes of a noob!