Can we set the ExceptionMessage in replace handler using resource files?

Topics: Exception Handling Application Block
Aug 31, 2009 at 12:21 PM

Can we set the ExceptionMessage in replace handler (Enterprise library) using resource files? if yes how?

I have an application named ResourceExample. This has a App_GlobalResources folder containing the MyResourceabc.resx which contains mapping of 

 "ErrorMessage" to "Server not found"

In the Default.aspx, i am throwin this error on button click for testing,


 ArgumentNullException ex = new ArgumentNullException("ErrorMessage");

throw ex;

But its not picking the Error String from the resource file!!

The config file is as follows:

      <add name="ExceptionPolicy">
          <add type="System.ArgumentNullException, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="ThrowNewException" name="ArgumentNullException">
              <add exceptionMessage="" exceptionMessageResourceName="MyResourceabc"
                exceptionMessageResourceType="Resources.MyResourceabc, App_GlobalResources.ha-7fil4, Version=, Culture=neutral, PublicKeyToken=null"
                replaceExceptionType="System.Exception, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ReplaceHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                name="Replace Handler" />

Please let me know if there is some thing which i did wrong...

Thanks in advance for the help,


Sep 1, 2009 at 4:01 AM

There's something wrong with the value of the exceptionMessageResourceType.  It should be the full typename of your resource file.  For example, if you placed your resx in the App_GlobalResources folder and your project namespace is MyWebApplication, the exceptionMessageResourceType value should be MyWebApplication.App_GlobalResources.MyResourceabc, MyWebApplciation, .....version info,etc.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Aug 12, 2010 at 2:48 PM

My Web Application project name: MyCompany.MyProject.UI.MySite
My resource name in the App_GlobalResources: Messages

I want to change the message of the exception from resource, but the following configuration doesn't work:


<add name="User Interface Exception Policy">
		<add name="DatabaseNotFoundException" type="MyCompany.General.Web.Exceptions.UserFirendly.DatabaseNotFoundException, MyCompany.General.Web.Exceptions, Version=, Culture=neutral, PublicKeyToken=null" postHandlingAction="None">
				<add name="Replace Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ReplaceHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
				exceptionMessageResourceType="MyCompany.MyProject.UI.MySite.App_GlobalResources.Messages, MyCompany.MyProject.UI.MySite" replaceExceptionType="MyCompany.General.Web.Exceptions.UserInterfaceException, MyCompany.General.Web.Exceptions, Version=, Culture=neutral, PublicKeyToken=null"/>

What is wrong with this configuration?

  I could not select the Resource from the Configuraiton Tool and I see that the generated class in the resx.cs is internal.


Aug 13, 2010 at 2:30 AM

If you directly add a resource file under the App_GlobalResources folder, its Build Action property is set to Content by default.  Change it to Embedded Resource.   Regarding the exceptionMessageResourceType, make sure it's correct.  The default namespace of a resource file under App_GlobalResources is Resources, so if you didn't change anything, your exceptionMessageResourceType  should be:

Resources.Messages, MyCompany.MyProject.UI.MySite

assuming MyCompany.MyProject.UI.MySite is the assembly name.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Aug 13, 2010 at 3:53 PM

Thanks! It is now working! I changed the namespace to Resources.Messages and set the postHandlingAction to ThrowNewException from None.