Unable to refer to a resource file from within app.config

Topics: Validation Application Block
Nov 1, 2010 at 12:02 PM

            My application contains several class libraries and one windows form application which is the UI and where app.config is. One of the class libraries is called BusinessLogic where I have created a resource file (ErrorMessages.resx) to store all error messages.

I am using Validation Application Block and as Microsoft suggests I want all validations to stay at app.config file. The problem is I am not able to display messages from the resource file(which is at BusnessLogic dll)  using MessageTemplateResourceType (from within app.config).

see below, my app.config,

<property name="ClientAddress">

                        <validatortype="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

                            upperBound="30" lowerBound="3" messageTemplate=""messageTemplateResourceName="StringLengthMsg"

                            messageTemplateResourceType="BusinessLogic.Resources.ErrorMessages, BusinessLogic, Version=, Culture=neutral, PublicKeyToken=null"

                            name="String Length Validator" />


I would really appreciate if someone can help, and also suggest whether the mechanism I am using is correct or not.

Thanks in advance.

Nov 2, 2010 at 12:52 AM

Make sure sure that that is the correct type name of your resource file.  Check the designer.cs file of your resx file to to verify the correct namespace.  Your .resx file's Build Action property should also be set to Embedded Resource.


Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.

Nov 2, 2010 at 8:05 AM

Thanks for the reply.

The Build Action property of the resource file is Embedded Resource. But as you've rightly mention there is something wrong in the resource type, if I just use "BusinessLogic, Version=, Culture=neutral, PublicKeyToken=null", (I use "GetType(BusinessLogic.My.Resources.ErrorMessages).Assembly.FullName.ToString" to get the type name) it says it can't find the assembly. 

Please let me know if you want any other information

Nov 2, 2010 at 8:25 AM

Did you open the designer.cs file of the resx file? Just copy the namespace, the full type name you should use then in the messageTemplateResourcType should be in this format:

namespace.resourceFileName, assemblyName


Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.

Nov 2, 2010 at 11:55 AM

Yes....That works...Thank you so much.

below is how it should be, I was missing the "My." 

<validator type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                            upperBound="0" lowerBound="3" messageTemplate="" messageTemplateResourceName="StringLengthMsg"
                            messageTemplateResourceType="BusinessLogic.My.Resources.ErrorMessages, BusinessLogic, Version=, Culture=neutral, PublicKeyToken=null"
                            name="String Length Validator" />

Thanks again.

Divyang Vyas