Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7951283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:30:54+00:00 2026-06-04T02:30:54+00:00

I working on a test program which to help me figure out how work

  • 0

I working on a test program which to help me figure out how work with the Microsoft.Practices.EnterpriseLibrary.ExceptionHandling framework works. The program defines several custom exception types and associates custom exception handlers with each type. At run time, the program prompts the user for the type of exception to throw, throws the exception, and uses the ExceptionHandling framework to call an appropriate exception handler for the exception type:

using System;
using System.Collections.Specialized;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration;

namespace ConsoleApplication1
{
    public class AException  : Exception  { public AException(string message)  : base(message) { } }
    public class BException  : Exception  { public BException(string message)  : base(message) { } }
    public class BBException : BException { public BBException(string message) : base(message) { } }

    public class WrapperException : Exception
    {
        public WrapperException(Exception innerException)
            : base("Wrapped exception: [" + innerException.Message + "]", innerException) { }
    }

    public class MyExceptionHandler<T> : IExceptionHandler
    {
        protected NameValueCollection Ignore { get; set; }
        public MyExceptionHandler(NameValueCollection ignore)
        {
            Ignore = ignore;
        }

        #region IExceptionHandler Members

        public virtual Exception HandleException(Exception exception, Guid handlingInstanceId)
        {
            if (exception is T)
            {
                Console.WriteLine("Exception Handled:");
                Console.WriteLine("  Expected Type : [{0}]", typeof(T).ToString());
                Console.WriteLine("  Actual Type   : [{0}]", exception.GetType().ToString());
                Console.WriteLine("  Message       : [{0}]", exception.Message);
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine("Unexpected Exception Type: [{0}]", exception.GetType().ToString());
            }
            return exception;
        }

        #endregion
    }

    [ConfigurationElementType(typeof(CustomHandlerData))]
    public class AExceptionHandler : MyExceptionHandler<AException>
    {
        public AExceptionHandler(NameValueCollection ignore) : base(ignore) { }
    }

    [ConfigurationElementType(typeof(CustomHandlerData))]
    public class BExceptionHandler : MyExceptionHandler<BException>
    {
        public BExceptionHandler(NameValueCollection ignore) : base(ignore) { }
    }

    [ConfigurationElementType(typeof(CustomHandlerData))]
    public class ExceptionHandler : MyExceptionHandler<Exception>
    {
        public ExceptionHandler(NameValueCollection ignore) : base(ignore) { }

        public override Exception HandleException(Exception exception, Guid handlingInstanceId)
        {
            var wrapper = new WrapperException(exception);
            return base.HandleException(wrapper, handlingInstanceId);
        }
    }


    class Program
    {
        static void ThrowSomething()
        {
            Console.Write("Enter the exception type: ");
            var x = Console.ReadLine();
            if (x.Equals("a"))
            {
                throw new AException(x);
            }
            else if (x.Equals("b"))
            {
                throw new BException(x);
            }
            else if (x.Equals("bb"))
            {
                throw new BBException(x);
            }
            else
            {
                throw new Exception(x);
            }
        }

        static void Main(string[] args)
        {
            ExceptionManager xm = EnterpriseLibraryContainer.Current.GetInstance<ExceptionManager>();
            while (true)
            {
                //xm.Process(ThrowSomething, "Policy");
                try
                {
                    ThrowSomething();
                }
                catch(Exception ex)
                {
                    Exception exToThrow = null;
                    if (ExceptionPolicy.HandleException(ex, "policy", out exToThrow))
                    {
                        if (exToThrow == null)
                        {
                            throw;
                        }
                        else
                        {
                            throw exToThrow;
                        }
                    }
                }
                Console.WriteLine();
            }
        }
    }
}

In the first iteration of this program, I used the ExceptionManager.Process() method to invoke my ThrowSomething() method. Using this method, everything worked great. I then modified the Main to use ExceptionPolicy.HandleException() instead. When I did this, I started getting this exception:

Unhandled Exception:
Microsoft.Practices.ServiceLocation.ActivationException: Activation
error occured while trying to get instance of type
ExceptionPolicyImpl, key “policy” —>
Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the
dependency failed, type =
“Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl”,
name
= “policy”. Exception occurred while: while resolving. Exception is: InvalidOperationException – The type ExceptionPolicyImpl has multiple
constructors of length 2. Unable to disambiguate.

My App.config file contains the following:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    </configSections>
    <exceptionHandling>
        <exceptionPolicies>
            <add name="Policy">
                <exceptionTypes>
                    <add name="AException" type="ConsoleApplication1.AException, ConsoleApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                        postHandlingAction="None">
                        <exceptionHandlers>
                            <add type="ConsoleApplication1.AExceptionHandler, ConsoleApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                                name="AExceptionHandler" />
                        </exceptionHandlers>
                    </add>
                    <add name="BException" type="ConsoleApplication1.BException, ConsoleApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                        postHandlingAction="None">
                        <exceptionHandlers>
                            <add type="ConsoleApplication1.BExceptionHandler, ConsoleApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                                name="BExceptionHandler" />
                        </exceptionHandlers>
                    </add>
                    <add name="All Other Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                        postHandlingAction="NotifyRethrow">
                        <exceptionHandlers>
                            <add type="ConsoleApplication1.ExceptionHandler, ConsoleApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                                name="ExceptionHandler" />
                        </exceptionHandlers>
                    </add>
                </exceptionTypes>
            </add>
        </exceptionPolicies>
    </exceptionHandling>
</configuration>

Can anyone tell me why I am getting this exception and how to resolve the problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:30:55+00:00Added an answer on June 4, 2026 at 2:30 am

    Well, I feel stupid. The problem was that spelled “policy” with a lowercase “p” instead of an uppercase “P”. Changing the line

    if (ExceptionPolicy.HandleException(ex, "policy", out exToThrow))
    

    to

    if (ExceptionPolicy.HandleException(ex, "Policy", out exToThrow))
    

    fixed the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on test framework, which creates a new app domain to
Working on a simple C program I'm stuck with an if test: int line_number
I'm working on a program which uses the System.Diagnostics.Debugger.Break() method to allow the user
Hey so I have test program for something I'm working on. What does it
I'm currently working on a tracking program which tracks hundreds of users at once,
I'm working on a program, which should list all files and it's size(for now...).
I'm working a program which is parsing some files and than process these files.
I am working on a c++ program which essentially just executes a lua script.
I'm actually working with a multi threaded program which involves lots of mysql operations,
I have added some animation using jquery but it's not working: $('.test-container').click(function(){ $(this).css('background-color', 'rgb(119,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.