Custom Handler not showing up in Config utility list of "loaded assemblies"

Topics: Building and extending application blocks, Exception Handling Application Block
Jan 21, 2011 at 4:00 PM
Edited Jan 21, 2011 at 4:33 PM

I have created a custom Handler that I hope to use for Exception Shielding in a WCF REST boundary. It is intended to take validation errors in a service operation call and return them as a WebFault to the mobile devices (these do not support SOAP, which is why we must use the WCF REST Contrib extensions), with the parameter and error message returned as named/value pairs in the message. I do not want any sensitive information, such as stack trace, to be returned to the client. The policy will be using the ArgumentException type and the custom Handler. It will not log the error.

It seemed simple enough, but for some reason isn't showing up in the Add Handlers/Add Custom Exception Handler list of loaded assemblies when I select the dll containing my custom handler.

The code is as follows:

namespace Application.Library
{
    [ConfigurationElementType(typeof(CustomHandlerData))]
    public class ArgumentExceptionWebFaultHandler : IExceptionHandler
    {
        public ArgumentExceptionWebFaultHandler(NameValueCollection ignore) { }

        public Exception HandleException(Exception exception, Guid guid)
        {
            var msg = new StringBuilder(exception.Message);

            if (exception is ArgumentException)
            {
                msg.Append(" -- |");

                foreach (var key in exception.Data.Keys)
                {
                    msg.Append(key.ToString().Trim() + ":" + exception.Data[key].ToString().Trim() + "|");
                }
            }

            return new WebFaultException<string>(msg.ToString(), HttpStatusCode.BadRequest);
         }
    }
}

 

Jan 24, 2011 at 12:52 AM

If the assembly where your custom exception handler is defined has already been previously loaded in the configuration tool, the configuration tool won't attempt to reload it again so it doesn't see the updated version of your assembly.  The workaround is to close and re-open Visual Studio.

 

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

Jan 24, 2011 at 5:24 PM

Opening and closing Visual Studio did not work. I opened the dll in ildasm and it is there... just won't list in the EntLib5 config tool when I open the file while attempting to load the custom handler.

Jan 25, 2011 at 10:34 AM

Hmm not really sure what is happening from your end. I've just tried to copy and paste your custom handler and it does work fine from my end. What happen if you try to reproduce the problem using your custom handler in a simple or maybe a console project?

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

Jan 25, 2011 at 4:53 PM

Interesting. It does show up in a standalone assembly.

Jan 25, 2011 at 5:08 PM
Edited Jan 27, 2011 at 4:35 PM

Ok... found the problem. It doesn't show up if the referenced assembly is signed.

Is this a bug?

Jan 26, 2011 at 4:23 AM

I can't repro the behavior, I can see a signed assembly listed in the config editor's type picker.  Do you have a small repro? 

 

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

Jan 28, 2011 at 2:03 AM

Actually, it is working now for some reason. Not sure why because I made no changes other than flipping the signing. After that, it doesn't seem to matter.