Error: multiple constructors of length 2

Topics: Exception Handling Application Block, Logging Application Block
Sep 7, 2011 at 2:22 PM
Edited Sep 7, 2011 at 2:25 PM

I am using EntLib 5 to do exception handling and logging:

 

 rethrow = ExceptionPolicy.HandleException(ex, "BusinessLogicPolicy");

 
 

Through this works, but still not 100% as we expect. So I want to step into the source code to take a look. What I did is including ExceptionPolicy.cs into our project and change the namespace to ours, and import EL ExceptionHandling at top:

 

using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;

 

But I still couldn't figure out. Then I include another 2 files: ExceptionPolicyImpl.cs and ExceptionPolicyEntry.cs and did the same change, but suddenly I get totally different error:

InvalidOperationException - The type ExceptionPolicyImpl has multiple constructors of length 2. Unable to disambiguate.

It seems it couldn't find the specified policy. But if I exclude these 2 files, I can get corret result although it is not perfect. The web.config is definitely in the root of application. Can someone tell me what happened behind?

 



 

 

Sep 7, 2011 at 2:55 PM

Hi,

Can you check if the PolicyName you are passing is defined on your configuration? 

 

Noel Angelo Bolasoc
Avanade Software
Avanade, Inc.
entlib.support@avanade.com

Sep 8, 2011 at 1:19 AM

Yes, the policy name is the same in the config: BusinessLogicPolicy. And as I said, if I don't include the source code into my project, everything works fine. But if I include those 2 files: ExceptionPolicyImpl.cs and ExceptionPolicyEntry.cs, I will get the above errors.

The line got error is in ExceptionPolicy.cs as below:

 

try
{
 //ExceptionManager em = EnterpriseLibraryContainer.Current.GetInstance<ExceptionManager>();
 return EnterpriseLibraryContainer.Current.GetInstance<ExceptionPolicyImpl>(policyName); --> Exception occurs
}
catch (ActivationException configurationException)
{
 try
 {
  DefaultExceptionHandlingEventLogger logger = EnterpriseLibraryContainer.Current.GetInstance<DefaultExceptionHandlingEventLogger>();
  logger.LogConfigurationError(configurationException, policyName);
 }
 catch { }
 throw;
}

But if I uncommented the line of ExceptionManager, I could see all policies when debugging. But the funny thing is if I include ExceptionManager.cs into my project and change the namespace to our own, i'll get error "The type ExceptionManager cannot be constructed. You must configure the container to supply this value". It seems I cannot include any source file into my project.

We use 3-Tiers structure, and the .dll of our exception handling project which uses EL Exception Handling block is in the application's bin folder. So I am not sure when application runs, it should go to web.config of application to detect all policies, is it?

Sep 8, 2011 at 2:55 AM

Hi,

I'm not sure of the reason why you need to add those files. If you need to step through Entlib source, then what you can do is to to grab the pdb files from the Entlib Source code and put it in the bin/Debug folder of your application. For the complete procedure kindly refer to this thread. Also note that you should be resolving from the ExceptionManager class and not ExceptionPolicyImpl for the Exception Handling to work as documented here. Hope this helps.

 

Noel Angelo Bolasoc
Avanade Software
Avanade, Inc.
entlib.support@avanade.com

Sep 8, 2011 at 6:39 AM

Thank you for your reply. I tried your ways. But I still couldn't step into the source. Below are the steps:

1. Put the all pdb files we need into application bin folder:

Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.pdb
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.pdb
Microsoft.Practices.EnterpriseLibrary.Caching.pdb
Microsoft.Practices.EnterpriseLibrary.Logging.pdb
Microsoft.Practices.EnterpriseLibrary.Logging.Database.pdb

2. Add the application bin folder path into VS 2010 Debug Symbols file location list.

But even I put a breakpoint into the line:

rethrow = ExceptionPolicy.HandleException(ex, "BusinessLogicPolicy");

I still couldn't step into the source code when clicking F11.

Also I change to ExceptionManager like below:

ExceptionManager em = EnterpriseLibraryContainer.Current.GetInstance<ExceptionManager>();
rethrow = em.HandleException(ex, "BusinessLogicPolicy");

It didn't work as well. All I want to is to step into the code. Did I miss sth?

Sep 8, 2011 at 7:13 AM

What does it prompt you when stepping into the breakpointed code?

 

Noel Angelo Bolasoc
Avanade Software
Avanade, Inc.
Contact Us

Sep 8, 2011 at 7:17 AM

Nothing. It went straight to my final block.

Sep 8, 2011 at 7:19 AM

And I didn't check "Just my code" in VS.

Sep 8, 2011 at 7:52 AM

I'm not really sure what's going on here but the steps should work. Basically it should prompt you for the source code. Try also to uncheck the "Require source files to exactly match the original version" from Tools > Options > Debugging > General if this will work. If the problem is still there then try to reset your VS settings (devenv /resetsettings)

 

Noel Angelo Bolasoc
Avanade Software
Avanade, Inc.
Contact Us