Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

When using Enterprise Library 6.0, this error occurs in the code below:

bool rethrow = ExceptionPolicy.HandleException(ex, "ReplacePolicy1")

"Must set an ExceptionManager in the ExceptionPolicy class using the SetExceptionManager method."

In Enterprise Library 5.0 this code worked:

public static bool HandleException(Exception exception, string PolicyName)
{
    ExceptionManager exManager = EnterpriseLibraryContainer.Current.GetInstance<ExceptionManager>();
    ExceptionPolicy.SetExceptionManager(exManager);
    bool rethrow = ExceptionPolicy.HandleException(ex, "ReplacePolicy1");
    return reThrow;
}

But in Enterprise Library 6.0 the EnterpriseLibraryContainer class is not found. I want get instance of ExceptionManager. How do I solve this problem ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
731 views
Welcome To Ask or Share your Answers For Others

1 Answer

EnterpriseLibraryContainer was removed for the release of Enterprise Library 6. There is a new approach for bootstrapping the application blocks in Enterprise Library 6. If you want to get an instance of ExceptionManager you can use the factory:

IConfigurationSource config = ConfigurationSourceFactory.Create();
ExceptionPolicyFactory factory = new ExceptionPolicyFactory(config);

ExceptionManager exManager = factory.CreateManager();

To configure the blocks to use the static facades you can use the SetExceptionManager method and supply the ExceptionManager from above:

ExceptionPolicy.SetExceptionManager(factory.CreateManager());

This only needs to be done once at application startup.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...