Enterprise Library Jan 2006 - custom exception formatter fails unless running debugger

D

David Herbst

Enterprise Library Jan 2006 with Visual Studio 2005 on Windows 2000
Server sp4.

My custom exception formatter fails with a "Unable to handle exception:
'LoggingExceptionHandler'." exception. When I attached the debugger to
the process and stepped into the code it executed without error. In
both cases I was running a Debug build, the only difference in the case
that works is that I attached the debugger to the same exact binaries.
Note: the error also occurs in a Release build.

*** Start excerpt from web.config ***

<exceptionHandling>
<exceptionPolicies>
<add name="General">
<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="Shared.WebTextExceptionFormatter,
Shared, Version=1.0.2213.28731, Culture=neutral, PublicKeyToken=null"
priority="0"
type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler,
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
name="Logging Handler" />
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>

*** End excerpt from web.config ***

*** Start Event Log entry ***

Event Type: Warning
Event Source: ASP.NET 2.0.50727.0
Event Category: Web Event
Event ID: 1309
Date: 1/22/2006
Time: 5:33:36 PM
User: N/A
Computer: abc3
Description:
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 1/22/2006 5:33:36 PM
Event time (UTC): 1/23/2006 1:33:36 AM
Event ID: b42e0b6c76d64c2c8a3cd9acdeac7a93
Event sequence: 30
Event occurrence: 1
Event detail code: 0

Application information:
Application domain: /LM/W3SVC/1/Root/Set-3-127824536009911250
Trust level: Full
Application Virtual Path: /Set
Application Path: D:\00-data\Dev\Settlement\www-set-development\
Machine name: abc3

Process information:
Process ID: 3432
Process name: aspnet_wp.exe
Account name: abc3\ASPNET

Exception information:
Exception type: ExceptionHandlingException
Exception message: Unable to handle exception:
'LoggingExceptionHandler'.

Request information:
Request URL: http://localhost/Set/Billing/ParticipantMessages.aspx
Request path: /Set/Billing/ParticipantMessages.aspx
User host address: 127.0.0.1
User: corporate\abc
Is authenticated: True
Authentication Type: NTLM
Thread account name: abc3\ASPNET

Thread information:
Thread ID: 7
Thread account name: abc3\ASPNET
Is impersonating: True
Stack trace: at
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry.ExecuteHandlerChain(Exception
ex, Guid handlingInstanceID)
at
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry.Handle(Exception
exceptionToHandle)
at
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl.HandleException(Exception
exceptionToHandle)
at
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception
exceptionToHandle, String policyName)
at Shared.BasePage.OnError(EventArgs e)
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext
context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.billing_participantmessages_aspx.ProcessRequest(HttpContext
context)
at
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously)


Custom event details:

*** End Event Log entry ***
 
D

David Herbst

It turns out that it also fails in the debugger, although only
intermittently.

I finally discovered that the problem was that the ServerVariables
collection was being changed while my custom formatter was doing a "for
each" loop to dump these variables into the exception message. I have
no idea what would cause the ServerVariables to change while the page
is being processed but I did the exact same "for each" loop on this
collection in .NET 1.1 for a year or more without encountering this
problem.

Anyway, the solution I implemented to solve this problem was to first
create a copy of the ServerVariables by instantiating a new
NameObjectKeysEnumerator object and passing in the ServerVariables
collection to the constructor. I can then iterate the copy of this
collection without it changing on me.

BTW a "Collection was modified after the enumerator was instantiated."
exception gets thrown by NameObjectKeysEnumerator.MoveNext() when this
happens but Enterprise Library catches the exception and throws a new
generic "Unable to handle exception: 'LoggingExceptionHandler'."
exception without assigning the lower level exception to the inner
exception property of the new exception. It would have saved me a lot
of time if Enterprise Library wrapped the old exception instead of just
creating a new meaningless generic one. Since this problem was
intermittent it wasn't easy to track this down even using a debugger.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top