How to use ExceptionManager

Topics: Exception Handling Application Block, Logging Application Block, Policy Injection Application Block
Jul 12, 2009 at 11:14 PM

I used PolicyInjection.Create<>() method to create new objects which i injected after/before method loggings. The problem is I need to log exception from these objects too. The EHAB only works when I use new to create new objects. It's mentioned in the guideline to use ExceptionManager, but I cannot find any example on how to use it. Can someone please help me with this?

Jul 13, 2009 at 3:42 AM

Are you saying that the ExceptionPolicy.HandleException method that is inside an object created by using PolicyInjection.Create doesn't work?  What I read from the doc is you must use the ExceptionManager if you used Unity when creating the object.  Anyway, there is a sample in the quickstart for exceptionhandling, it's in the folder CS - Unity Integration. 


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

Jul 13, 2009 at 9:16 PM

I found the quick start project. Thanks. The msdn tutorial seems to be a bit un-synched with the quick start samples.  

I have another problem here. I have a WCF service and it calls the DAL layer (userDAO) to retrieve data.
Here is the code in the wcf service constructor to create a userDAO instance.

public MyService()
  IUnityContainer container = new UnityContainer();
  UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
  userDAO = container.Resolve<

The constructor for UserDAO is 
public UserDAOBase(ExceptionManager exceptionManager)
     dataContext = new  DataContext();
     this.exceptionManager = exceptionManager;


Following is the error I got when calling container.Resolve:

Resolution of the dependency failed, type = "Database.DAO.UserDAO", name = "". Exception message is: The current build operation (build key Build Key[Database.DAO.UserDAO, null]) failed: The parameter exceptionManager could not be resolved when attempting to call constructor Database.DAO.UserDAO(Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionManager exceptionManager). (Strategy type BuildPlanStrategy, index 3)


I am not sure with ExceptionManager is not automatically generated this time as in the sample?


Jul 13, 2009 at 11:05 PM

Did you add the exception block extension to your Unity configuration? There's an extension per block.


Jul 16, 2009 at 3:03 PM

It works when I change the references. The dlls in the  EntLib41Src/bin don't have signatures and causes the loading error. Thanks.

By the way, is there any statistics about the performance panelty using container.resolve to create objects especially in WCF where the mode is set to per-call, which create a new instance on every client request?   Thanks for the help.