Constructor on type on Custom Handler error

Topics: Exception Handling Application Block
Jun 16, 2010 at 5:37 PM

I am getting the following constructor error with my custom handler. What is causing this? Thank you -dave

Constructor on type 'MyExceptionHandler.MyLoggingExceptionHandler' not found.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.MissingMethodException: Constructor on type 'MyExceptionHandler.MyLoggingExceptionHandler' not found.

 

Configuration....(web.config)

  <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
    defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add source="Enterprise Library Logging" formatter="Text Formatter"
        log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=9730ada91d7fa2ae"
        traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=9730ada91d7fa2ae"
        name="Formatted EventLog TraceListener" />
    </listeners>
    <formatters>
      <add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=9730ada91d7fa2ae"
        name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Formatted EventLog TraceListener" />
        </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="Formatted EventLog TraceListener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
  <exceptionHandling>
    <exceptionPolicies>
      <add name="Exception Policy">
        <exceptionTypes>
         
          <add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="NotifyRethrow"
            name="Exception">
          <!--
            <exceptionHandlers>
              <add logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
                formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=9730ada91d7fa2ae"
                priority="0" useDefaultLogger="false" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=9730ada91d7fa2ae"
                name="Logging Handler" />
            </exceptionHandlers>
            -->
            <exceptionHandlers>
              <add
                type="MyExceptionHandler.MyLoggingExceptionHandler, MyExceptionHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9730ada91d7fa2ae"
                name="Custom Handler" />
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
    </exceptionPolicies>
  </exceptionHandling>

 

Custom Handler

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Xml;
using System.IO;
using System.Diagnostics;
using System.Net.NetworkInformation;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using Microsoft.Practices.EnterpriseLibrary.Logging.ExtraInformation;

namespace MyExceptionHandler {
    /// <summary>
    /// The custom Exception Handler for the Critical Error Reporting Framework
    /// </summary>
    [ConfigurationElementType(typeof(CustomHandlerData))]
    public class MyLoggingExceptionHandler : IExceptionHandler {
        /// <summary>
        /// An internal event Id holder to be used when logging the exception
        /// </summary>
        private static int _eventId = 0;
        /// <summary>
        /// The synchronization object for the event Id
        /// </summary>
        private object _syncEventId = new object();
        /// <summary>
        /// The CTOR for the Exception Handler. 
        /// </summary>
        /// <param name="ignore">The name value collection holds parameters from the config tool.  This is unused but necessary to implement the custom exception handler.</param>
        public MyLoggingExceptionHandler(NameValueCollection ignore):base(){
        }
        public MyLoggingExceptionHandler() {
        }
        /// <summary>
        /// Get the next event identifier
        /// </summary>
        /// <returns>the next event identifier</returns>
        private int GetNextEventId() {
            lock (_syncEventId) {
                return _eventId++;
            }
        }
        /// <summary>
        /// Process the exception being handed to the handler
        /// </summary>
        /// <param name="exception">the exception to be processed</param>
        /// <param name="handlingInstanceId">the GUID for the handling instance chain</param>
        /// <returns>The exception as passed in. No modification occurs to the exception.</returns>
        public Exception HandleException(Exception exception, Guid handlingInstanceId) {
            // Perform processing here. The exception returned will be passed to the next
            // exception handler in the chain.
            // Use the handling instance Id for the Issue Tag for this error
            Guid issueTag = handlingInstanceId;
            string xmlExceptionData = "";
            // create a memory stream to hold the resulting xml
            //using (MemoryStream memStream = new MemoryStream()) {
            //    // initialize the ExceptionFormatter for the critical error reporting
            //    CriticalErrorExceptionFormatter formatter =
            //        new CriticalErrorExceptionFormatter(memStream, exception);
            //    // format the exception into the stream
            //    formatter.Format();
            //    // get the encoded stream as a string
            //    xmlExceptionData = Encoding.UTF8.GetString(memStream.ToArray());
            //}

            // set up a dictionary for extended information
            Dictionary<string, object> dictionary = new Dictionary<string, object>();

            // get the managed security context information for the exception
            ManagedSecurityContextInformationProvider mgdInfoProvider =
              new ManagedSecurityContextInformationProvider();
            mgdInfoProvider.PopulateDictionary(dictionary);

            // get the unmanaged security context information for the exception
            UnmanagedSecurityContextInformationProvider unmgdInfoProvider =
                new UnmanagedSecurityContextInformationProvider();
            unmgdInfoProvider.PopulateDictionary(dictionary);

            // get the com plus information for the exception
            ComPlusInformationProvider complusInfoProvider =
                new ComPlusInformationProvider();
            complusInfoProvider.PopulateDictionary(dictionary);

            // now log the exception
            LogEntry logEntry = new LogEntry();
            logEntry.EventId = GetNextEventId();
            // Set the Severity to Critical so that our logging handler picks it up
            logEntry.Severity = TraceEventType.Critical;
            logEntry.Priority = 2;
            logEntry.Message = xmlExceptionData;
            // Add the Critical Error Reporting Framework category
            logEntry.Categories.Add("Critical Error Reporting Framework");

            // add in the additional information from the providers
            logEntry.ExtendedProperties = dictionary;

            // add the issue tag to the extended properties of the log entry
            logEntry.ExtendedProperties.Add("IssueTag", issueTag);

            // get the MAC address to use as the site code
            NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
            if (interfaces.Length > 0) {
                //use the first one as the site code
                string macAddress = interfaces[0].GetPhysicalAddress().ToString();
                logEntry.ExtendedProperties.Add("SiteCode", macAddress);
            }

            // write to the reporting service
            Logger.Write(logEntry);

            // just return the initial exception
            return exception;
        }

    }
}

 

 

Jun 17, 2010 at 3:55 AM

Hi,

I noticed that you're using your own entlib signed assemblies. Unfortunately, I'm unable to reproduce your problem using the authentic entlib signed assemblies and your Custom Exception Handler works fine from my end. Would you know what are the exact changes in your signed assemblies that you think may have affect this?

Gino Terrado
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

 

Jun 17, 2010 at 1:02 PM
I only signed the enterprise library dll's with our company public/private key. Nothing more at all. With that being said, why would using signed dll's make any difference? (something doesn't make sense) -dave
Jun 18, 2010 at 2:44 AM

Probably just thought you made some changes in the code which could have caused the exception but since you now said you didn't do any code changes, then we'll rule it out.

I also don't see anything wrong with your code or configuration.  The required constructor is the one which takes a NameValueCollection parameter and you're MyLoggingExceptionHandler has it.  Are you sure you're using the version of your custom exception handler which has that constructor?

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jun 22, 2010 at 2:08 PM
Edited Jun 22, 2010 at 6:56 PM

n/a

Jun 22, 2010 at 2:10 PM
Edited Jun 22, 2010 at 6:56 PM

n/a

Jun 22, 2010 at 3:40 PM
Edited Jun 22, 2010 at 6:56 PM

n/a

Jun 22, 2010 at 6:52 PM
Edited Jun 22, 2010 at 7:00 PM

I moved the project/solution to a new pc and things worked ok.  My work pc however there is some conflict?

On my workstation i get the following exception still.
 
I have made all references for dll's to the bin directory to ensure they are used.  I set the startup page to Test.aspx
 
I have tried many things...
 - renamed any other local ent lib dll directories
 - removed ent lib dll's from gac
 - copied machine.configs from good pc to bad pc
 
I am at a loss now as to what would be conflicting on my local pc (would there be anything in registry ???) (anything on local pc or visual studio telling it to use something for dlls look up?)

Is there somewhere i can email the solution?
 

Constructor on type 'MyExceptionHandler.MyLoggingExceptionHandler' not found.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.MissingMethodException: Constructor on type 'MyExceptionHandler.MyLoggingExceptionHandler' not found.

Source Error:

Line 20:             } catch (Exception ex) {
Line 21: 
Line 22:                 bool rethrow = ExceptionPolicy.HandleException(ex, "Exception Policy");
Line 23:                 if (rethrow)
Line 24:                     throw;


Source File: C:\Temp\oliveoil\Handler\Handler\Handler.WebSite\Test.aspx.cs    Line: 22

Stack Trace:

[MissingMethodException: Constructor on type 'MyExceptionHandler.MyLoggingExceptionHandler' not found.]
   System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +1051
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +111
   System.Activator.CreateInstance(Type type, Object[] args) +16
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.CustomProviderAssembler`3.Assemble(IBuilderContext context, TConfiguration objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) +196
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.AssemblerBasedObjectFactory`2.Create(IBuilderContext context, TConfiguration objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) +171
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntryCustomFactory.Create(IBuilderContext context, ExceptionTypeData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) +192
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyCustomFactory.CreateObject(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) +225
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy.PreBuildUp(IBuilderContext context) +290
   Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +119

[BuildFailedException: The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl, Exception Policy]) failed: Constructor on type 'MyExceptionHandler.MyLoggingExceptionHandler' not found. (Strategy type ConfiguredObjectStrategy, index 2)]
   Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +349
   Microsoft.Practices.ObjectBuilder2.Builder.BuildUp(IReadWriteLocator locator, ILifetimeContainer lifetime, IPolicyList policies, IStrategyChain strategies, Object buildKey, Object existing) +102
   Microsoft.Practices.ObjectBuilder2.Builder.BuildUp(IReadWriteLocator locator, ILifetimeContainer lifetime, IPolicyList policies, IStrategyChain strategies, Object buildKey, Object existing) +52
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp(IReadWriteLocator locator, ILifetimeContainer lifetimeContainer, String id, IConfigurationSource configurationSource) +615
   Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.LocatorNameTypeFactoryBase`1.Create(String name) +160
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.GetExceptionPolicy(Exception exception, String policyName, ExceptionPolicyFactory factory) +89

[ExceptionHandlingException: The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl, Exception Policy]) failed: Constructor on type 'MyExceptionHandler.MyLoggingExceptionHandler' not found. (Strategy type ConfiguredObjectStrategy, index 2)]
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.GetExceptionPolicy(Exception exception, String policyName, ExceptionPolicyFactory factory) +304
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName, ExceptionPolicyFactory policyFactory) +76
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName) +216
   Handler.WebSite.Test.Page_Load(Object sender, EventArgs e) in C:\Temp\oliveoil\Handler\Handler\Handler.WebSite\Test.aspx.cs:22
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

 

Jun 23, 2010 at 1:17 AM

I'm not sure but the only thing I can think of is difference in the version of the assembly where you're custom exception handler is in.

I would like to check out your solution, are you sending it using .zip format?  We're able to receive .zip files in our email.  If that doesn't work, probably you need to use a different email to send that.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jun 23, 2010 at 2:37 AM

It worked fine on my machine.   Wasn't there any inner exception?

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jun 23, 2010 at 1:14 PM
There wasn't an inner exception. The solution just simply ensured that the custom handler was indeed called. Yes, it worked ok on my home pc.

Is there any way of tracking what the system is doing (while it hits the exception?) I am at a loss as to why there is an issue on my work pc.

thank -dave


From: [email removed]
To: [email removed]
Date: Tue, 22 Jun 2010 19:37:10 -0700
Subject: Re: Constructor on type on Custom Handler error [entlib:216263]

From: AvanadeSupport
It worked fine on my machine. Wasn't there any inner exception?

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Read the full discussion online.
To add a post to this discussion, reply to this email (entlib@discussions.codeplex.com)
To start a new discussion for this project, email entlib@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Hotmail has tools for the New Busy. Search, chat and e-mail from your inbox. Learn more.
Jun 24, 2010 at 8:17 AM

I don't know any tools if there is any. How about debugging it in the workstation where the App doesn't work using PDB files just to help us pinpoint where exactly the exception is raised. You can find some helpful tips from this thread http://entlib.codeplex.com/Thread/View.aspx?ThreadId=39988.  

And to re-iterate the steps from the thread, here are the steps on how you can use PDB files for debugging.  

1. Copy the .pdb file where the class you wish to debug belongs to the bin/Debug folder of your project.  
2. Open your project and in the Tools menu in VisualStudio, select Options. 
3. Go to the Debugging -> Symbols node. 
4. Click the folder icon and specify the path where you placed the .pdb file in the Symbol file (.pdb) locations listbox.
5. Click Ok.
6. Place a breakpoint in your app and then run it.
7. Press F11 upon hitting the breakpoint. 
8. You will then be prompted for the location of the class you wish to debug. You can easily locate that since you can see its original location in the dialog box. 

That's it.  
  

Gino Terrado
Global Technology and Solutions
Avanade, Inc.
 entlib.support@avanade.com