Reading messages from a resource file for exception messages

Topics: Exception Handling Application Block
Jan 27, 2010 at 9:25 AM


I've just start working with Exception Handling Application Block and I've got some questions that hope someone could answer me.

I've created a Data Access Policy  with SqlException and a wrap handler. When an exception is handlered I throw a new DataLayerException, now I want to add a personal message to the exception but not using ExceptinoMessage property because all the messages are in a resource file call Messages.resx.

The problem I have is that I don't know how to access to the resource file, I thought I had to use ExceptionMessageResourceName and ExceptionMessageResourceType, but I don't know how!!

Sorry about my English but I'm Spanish. I hope  you have understood something.

Have a good day!!

Jan 27, 2010 at 10:07 AM

Yes, you need to use the ExceptionMessageResourceName and ExceptionMessageResourceType.  The ExceptionMessageResourceName corresponds to the key of the resource string you want to use.  The ExceptionMessageResourceType is your resource file.


Sarah Urmeneta

Global Technology and Solutions

Avanade, Inc.


Jan 27, 2010 at 11:28 AM

I think there is something I'm missing.

I have a  web aplication with aspx pages and a global resource file Messages.resx

 When I try to select a ExceptionMessageResourceType from a property window with the button ... appear a lot of assemblies or files to choose but I cannot choose a .resx file.  Do I have to do something else to make Messages.resx accesible from this option?

Thank you,

P.D.: Sahah, you have a basque last name?

Jan 28, 2010 at 2:42 AM
Edited Jan 28, 2010 at 2:43 AM

You can't choose .resx files, only .dll files.  I specify it through the xml editor by typing the fully qualified name of the resource file as the resource file don't have an output assembly (although there is a tool I think which can generate that), e.g.

exceptionMessageResourceType="MyWebApplication.Properties.Messages, MyWebApplication"


Oh, on your comment on my last name, I don't know its origin either, :)

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Jan 29, 2010 at 7:31 AM

I dont´t get any results!! I'm going crazy!!

When the Messages.resx is selected in the solution Explorer I can see the in Properties window that Custom Tool Namespace is My.Resources, so I suppose that is the namespace of my resource file. For example I import this resource file to a .aspx page with 

<font size="2"><font size="2">


</font></font><font size="2">



Imports MyWebApplication.My.Resources.Messages

 (I know it's not neccesary becaues I have direct access to Resources namespace but it's just to try)

So I try in all these ways, but I cannot read the message!










When I write something in the ExceptionMessage properties it's OK, so now it's empty, and the message i've got is an empty message, can it be due to being ExceptionMessage=""??

Do you know what's wrong? Please, I need help.


About your last name, I'm sure that it's basque, it's sound really really basque.


Jan 29, 2010 at 8:13 AM

To determine the fully qualified name of your resource file, open the designer.cs of your .resx file, you'll see the exact namespace. 

By the way, what is the value of your PostHandlingAction?  Is it ThrowNewException?


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Jan 29, 2010 at 8:44 AM

I've a look in the designer.vb of Messages.resx, and the Namespace is My.Resources.

Now  I've done two resources file, one in the folder App_GlobalResources and the other outside this. In the first case the namespaces is Resources and in the second case My.Resources. So I try writting both in exceptionMessageResourceType, but nothing happens.

About the PostHandlingAction, it's value is ThrowNewException. I catch and "Exception" type exception and I throw an "ApplicationException" in Wrap Handler, just to try with one.

This is what I have:

<add name="Data Access Policy">


<add type="System.Exception, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"

postHandlingAction="ThrowNewException" name="Exception">


<add exceptionMessage="" exceptionMessageResourceType="Resources.Messages"

exceptionMessageResourceName="param" wrapExceptionType="System.ApplicationException, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"

type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WrapHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

name="Wrap Handler" />





Jan 29, 2010 at 8:49 AM

I just noticed, you didn't specify the fully qualified name.  You have to add the assembly name like this:

exceptionMessageResourceType="MyWebApplication.Resources.Messages, MyWebApplication"

I think you used dot instead of comma in your previous reply.

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Jan 29, 2010 at 8:59 AM

Great !!!!  That's it, the las one wasn't a dot , it was a comma, and i used a dot. I'm been fighting with this for days!! Thank you Sarah!!! You've been very patient!!

So, the solution is:

exceptionMessageResourceType="MyWebApplication.Resources.Messages, MyWebApplication"


Thak's a lot!! This is a really eficient community!


Jan 29, 2010 at 9:37 AM

One last question. The above solution works when the Message.resx is in the same level of web.config.  But If it's in App_GlobalResources doesn't work, and I want to set all my Global resources in this folder.

As I still don't understand the structure of the property exceptionMessageResourceType, I try to write the folder name same where, but nothing happens.

The namespace of the resource file in the folder is Namespace Resources while the one of the outside resoursce file was My.Resources.

What should I change?

Jan 29, 2010 at 9:50 AM

If you're moving your resource file to a different folder, make sure you update the exceptionMessageResourceType as well.  In your example, if you moved it under the App_GlobalResources folder, its namespace will change appended with the .App_GlobalResources word. Thus, it changes to

exceptionMessageResourceType="MyWebApplication.App_GlobalResources.Messages, MyWebApplication"


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Jan 29, 2010 at 10:58 AM

It doen't work. If I open Messages.Designer.vb the namespace it's the same as before, the App_GlobalResources word doesn't appear in it, so should i set the App_GlobalResources word there?

But there is also something strange, the namespace are diferent if I create the resource file under the App_GlobalResources folder, or if I move one created outside, to that folder. I'm trying with both, but nothing happens.

Jan 29, 2010 at 11:58 AM

Yeah, I've noticed that too, the namespaces thing, I think that's just how it's designed in vs.  Anyway, what's weird is I can't seem to make it work when the resource file is directly added in the App_GlobalResources folder as compared to when you just moved it there.  In short, it doesn't seem to work when it's under the Resources namespace.  Or maybe I missed something.   Anyway, I'll look into this more and let you know.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Feb 1, 2010 at 10:26 AM


Can you please try the pattern [namespace].[classname], [assemblyname]. It works on my end with the resx file inside the App_GlobalResources. We can also send you a sample solution.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.

Feb 1, 2010 at 2:18 PM


I have tried but It does not work for me, I 'll be greatful if you send me a sample solution you mentioned to

Thank you for everything

Feb 2, 2010 at 8:28 AM

Ok, my mistake.  I have a .resx file outside the App_GlobalResources folder containing the same resource key and value as with the one in inside that folder.  It was retrieving the information from there and not from the one in the App_GlobalResources folder.  We'll investigate more on this.

Feb 2, 2010 at 8:34 AM

Found out why it wasn't able to see the one from the App_GlobalResources folder.  If you add a .resx file directly under it, the BuildAction property is set to "Do Not Copy".  Change this to "Embedded Resource" and everything works fine.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Feb 5, 2010 at 12:29 PM

I am trying it but it does not work. In tthe property BuildAction of the resx file I have not "Do Not Copy" option and it was set to "Content". Anyway I will try again, because I have not time now.


Feb 8, 2010 at 2:20 AM

You should set it to "Embedded Resource", not to "Content".


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.