Error: The type ExceptionPolicyImpl has multiple constructors of length 2. Unable to disambiguate.

Topics: Exception Handling Application Block, Logging Application Block
Sep 2, 2011 at 6:03 PM

details of the error message are:

Type : System.InvalidOperationException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : The type ExceptionPolicyImpl has multiple constructors of length 2. Unable to disambiguate.
Source : Microsoft.Practices.Unity
Help link :
Data : System.Collections.ListDictionaryInternal
TargetSite : System.Reflection.ConstructorInfo FindLongestConstructor(System.Type)
Stack Trace :    at Microsoft.Practices.ObjectBuilder2.ConstructorSelectorPolicyBase`1.FindLongestConstructor(Type typeToConstruct)
   at Microsoft.Practices.ObjectBuilder2.ConstructorSelectorPolicyBase`1.SelectConstructor(IBuilderContext context, IPolicyList resolverPolicyDestination)
   at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context)
   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
   at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, NamedTypeBuildKey buildKey)
   at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)
   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)

the logging and exception handling in the web.config is:

  <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
    <listeners>
      <add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
       listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
       source="Enterprise Library Logging" formatter="Text Formatter"
       log="" machineName="." traceOutputOptions="None" />
      <add name="Database Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      databaseInstanceName="LocalSqlServer" writeLogStoredProcName="WriteLog"
      addCategoryStoredProcName="AddCategory" traceOutputOptions="Timestamp"
      filter="Information" />
    </listeners>
    <formatters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
       template="Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}"
       name="Text Formatter" />
    </formatters>
    <logFilters>
      <add minimumPriority="0" maximumPriority="1" type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.PriorityFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    name="Priority" />
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        enabled="true" name="Logging Enabled Filter" />
    </logFilters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Event Log Listener" />
        </listeners>
      </add>
      <add switchValue="Information" name="Information">
        <listeners>
          <add name="Database Trace Listener" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events" />
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Event Log Listener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
  <connectionStrings>
    <remove name="LocalSqlServer"/>
    <add name="LocalSqlServer" connectionString="data source=SQL-06-Dflt;Integrated Security=SSPI;initial catalog=VR_Logging"
    providerName="System.Data.SqlClient" />
  </connectionStrings>
  <exceptionHandling>
    <exceptionPolicies>
      <add name="Logging">
        <exceptionTypes>
          <add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
           postHandlingAction="NotifyRethrow">
            <exceptionHandlers>
              <add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
               logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
               formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
               priority="0" />
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
    </exceptionPolicies>
  </exceptionHandling>

This error is only occurring when Logger.Write is called on a background thread.

Any help is much appreciated.  Thanks.

 

Sep 5, 2011 at 2:29 AM

Hi,

Is this config defined inside your running application? Does this also occur if not inside the background thread? If this are not the case can you paste here the relevant code?

 

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

 

Sep 5, 2011 at 6:32 PM

Thanks for you response.

This config is defined inside the running application.  The problem does not occur outside the background thread.  Also, inside the background thread, the problem is intermittent.

Sep 6, 2011 at 2:18 AM

I was unable to reproduce it in our side. Maybe it would be a better if you could share us the code where the exception is thrown.

 

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

Sep 6, 2011 at 1:17 PM

There are two ajax calls on an aspx page:

$(document).ready(function () {
    DoWork();
});


function DoWork() {

    $.ajax({
        type: "POST",
        url: "PaymentReceived.aspx/VerifyIdentity",
        data: "",
        contentType: "application/json; charset=utf-8",
        dataType: "json",

        error: function (xhr) {
            var msg = eval('(' + xhr.responseText + ')').Message;
            alert(msg);
        },

        success: function (msg) {
            window.setTimeout(function () { GetStatus(); }, 100);
        }

    });                /* End $.ajax({ */
}

 


function GetStatus() {

    $.ajax({
        type: "POST",
        url: "PaymentReceived.aspx/GetInfo",
        data: "",
        contentType: "application/json; charset=utf-8",
        dataType: "json",

        error: function (xhr) {
            var msg = eval('(' + xhr.responseText + ')').Message;
            alert(msg);
        },

        success: function (msg) {

            if (msg.d.Url && msg.d.Url.length > 0) {
                window.location = msg.d.Url;
                return;
            }

            if (msg.d.Failed == true) {
                alert('Error in processing');
            }
            else {
                window.setTimeout(function () { GetStatus(); }, msgTimer);
            }


        }

    });         /* End $.ajax({ */
}

Here are the corresponding web methods:

    public partial class PaymentReceived : WizardBase
    {

        [WebMethod(EnableSession = true)]
        public static void VerifyIdentity()
        {
            new LexisNexusTask(HttpContext.Current).Run();

        }

        [WebMethod(EnableSession = true)]
       public static TaskInfo GetInfo()
        {
            return LexisNexusTask.GetInfo(HttpContext.Current);
        }
    }

Here is the start of the background thread:

 

public void

Run()

{

 

new System.Threading.Thread

(DoWork).Start();

}

Here is a portion of the  method on the background thread where I am trying to do the logging:

    private void DoWork()
        {
            try
            {
                RaiseStatusChanged("Starting LexisNexis", String.Empty, Request, Info);
                Logger.Write("Starting LexisNexis task for " + Request.RequestCode, "Information", 2);

                if (Request.OrderMethodTypeID == (int)OrderMethodType.Web)
                {
                    if (Info == null)
                    {
                        PaymentInformation payInfo = null;
                        int Retries = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Retries"]);
                        int RetryTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["RetryTimeout"]);
                        ServiceAppReference.ServiceAppClient client;
                        do
                        {
                            client = new ServiceAppReference.ServiceAppClient();
                            try
                            {
                                payInfo = client.GetPaymentInfo(Request.PaymentToken, Request.PaymentInformation);
                                client.Close();
                                break;

                            }
                            catch
                            {
                                client.Abort();
                            }
                            if (payInfo == null)
                            {
                                if (Retries <= 0)
                                    throw new Exception("Could not retrieve payment information");
                                else Thread.Sleep(RetryTimeout);
                            }
                        }
                        while (Retries-- > 0);


                        Request.PaymentInformation = payInfo;
                        RaiseStatusChanged("Got payment information", String.Empty, Request, null);
                        Logger.Write("Got payment information for " + Request.RequestCode, "Information", 2);
      ...
      }
      ...
      
     }
     }
     catch {
     }
   ... 

}

RaiseStatusChanged will update the HttpRuntime.Cache which is then queried in the web method GetInfo().

Please let me know if you require further information.  Thanks!

Sep 7, 2011 at 4:03 AM

Have you used Exception Handling somewhere in your code? Can you post it here too? It seems the error is originating from your exception handling.

 

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

Sep 7, 2011 at 5:05 AM
Edited Sep 7, 2011 at 5:15 AM

I believe you have found something there. When an error occurs on the background thread, I am serizalizing it and passing it to the UI thread.


MemoryStream stream = new MemoryStream(taskInfo.ErrorData, 0, taskInfo.ErrorData.Length, true);
BinaryFormatter formatter = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.Persistence));
transferredException = (Exception)formatter.Deserialize(stream);
ExceptionPolicy.HandleException(transferredException, "Log and Continue");


However, the exception policy "Log and Continue" was not defined in the configuration file that I sent you. Could this be the source of the error?


In global.asax, I have
protected void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError().GetBaseException();
if (ex is System.ServiceModel.FaultException)
{
AppServiceFault fault = ((System.ServiceModel.FaultException<AppServiceFault>)(ex)).Detail;
if (fault != null)
{
ExceptionPolicy.HandleException(new Exception(fault.FaultMessage, ex), "Logging");
}
else
{
ExceptionPolicy.HandleException(ex, "Logging");
}
}
else
{
ExceptionPolicy.HandleException(ex, "Logging");
}
Server.Transfer("~/wizard/ErrorPage.aspx");
}


Again, thank you for your assistance.

 

Sep 7, 2011 at 8:49 AM

Hi,

That would be the cause. You should specify a defined policy name from your configuration for the Handling Block to use or else it will throw an exception like the one you encountered (since it can't find the policy to use, it doesn't know how to handle the exception). Hope this helps :)

 

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

 

Sep 7, 2011 at 2:32 PM

I was able to reproduce the error with this information.  We can consider this issue closed.  Thanks so much for your assistance.