How to change wrapper mesg programmatically?

Topics: Exception Handling Application Block
Jun 23, 2009 at 12:04 PM

Any exception in my application should be wrapped.

In EL, we hardcode the wrapper message for a wrap handler.

But I need the wrapper msg to change programmatically.

Ie; say the exception from method1 is ‘file not found’, the wrapper msg would be ‘Application encountered error. Please choose another path and retry’ and if caught in another method say method2, the wrapper msg should be ‘Fatal error’

The point is, for the same exception type, I might need more than one wrapper msg based on where the exception is caught from. Is it possible to change the wrapper msg of a wrap handler programmatically? Can we have the messages as a key-value pair in a resource file or db from where it could be fetched based on a key?

Jun 24, 2009 at 5:07 AM

Hi,

One thing I can think of about this scenario is that you can implement you're custom handler which is similar to the built-in wraphandler. But does some processing(determining the correct wrapmessage) before doing the real WrapException. It may look something like this:

        public Exception HandleException(Exception exception, Guid handlingInstanceId)
        {
            string wrapExceptionMessage = DetermineCorrectWrapMessage(exception);
            return WrapException(exception, wrapExceptionMessage);
        }
Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

 

Jun 24, 2009 at 6:07 AM

Thanks. May i know what the handlingInstanceId is for???

Also i get this exception on the call of teh HandleException method.

{System.TypeInitializationException: The type initializer for 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null'
   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy..cctor()

=== Pre-bind state information ===
LOG: User = CHNMCT90321\ASPNET
LOG: DisplayName = Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/Inetpub/wwwroot/Tomra.Enterprise.PS.WCF/
LOG: Initial PrivatePath = C:\Inetpub\wwwroot\Tomra.Enterprise.PS.WCF\bin
Calling assembly : Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Inetpub\wwwroot\Tomra.Enterprise.PS.WCF\web.config
LOG: Using host configuration file: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet.config
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files/ps_wcf/fc3d3c49/589131ba/Microsoft.Practices.EnterpriseLibrary.Common.DLL.
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files/ps_wcf/fc3d3c49/589131ba/Microsoft.Practices.EnterpriseLibrary.Common/Microsoft.Practices.EnterpriseLibrary.Common.DLL.
LOG: Attempting download of new URL file:///C:/Inetpub/wwwroot/Tomra.Enterprise.PS.WCF/bin/Microsoft.Practices.EnterpriseLibrary.Common.DLL.
WRN: Comparing the assembly name resulted in the mismatch: PUBLIC KEY TOKEN
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

   --- End of inner exception stack trace ---
   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName)
   at Tomra.Enterprise.PS.DAO.RequestAuthorizationDAO.HandleException(Exception ex, String Policy) in D:\Michigan\SourceCode\Tomra.Enterprise.PS.DAO\RequestAuthorizationDAO.cs:line 90} 

Jun 24, 2009 at 6:20 AM

HandlingInstanceId is the id generated by the block to track exception. The error you've encountered, seems like you referenced the assemblies that is unssigned. is it?