Using resources in configuration file for VAB

Topics: Validation Application Block
Aug 15, 2007 at 1:00 AM
I have been unable to use resources when setting up the rules of the validation application block in a config file.

I am not sure how to handle the MessageTemplateResourceTypeName field.

I previously had this set up inline inside my class. The syntax was:

<StringLengthValidator(0, 500, MessageTemplateResourceName:="MaxCharsViolatedString", MessageTemplateResourceType:=GetType(Resources.ValidationStrings), Ruleset:="DBRules">

I have tried to use the same syntax (namely, GetType(Resources.ValidationStrings)) in the conf file, but this isn't working. I have also tried "Resources.ValidationStrings", but this didn't work either.

Any suggestions?

Thanks!

Aug 15, 2007 at 2:11 AM
Hi,

The type name in the configuration file should be the assembly qualified type name, i.e. [namespace].[class name], [assembly name], Version=[version], Culture=[culture], PublicKeyToken=[token].

I see you're using VB.NET, so the namespace is usually [default namespace].My.Resources. The problem here is that the resource retrieval code will only work if the class name matches the resources file name, so you will need to clear the "Custom Tool Namespace" property for the resx file in your project so this mach occurs.

Hope this helps,
Fernando
Aug 15, 2007 at 4:42 PM
Hi Fernando,

I am not seeing the "Custom Tool Namespace" property anywhere associated with the resx file. The file is currently in the App_GlobalResources directory (I assume this is where it should be).

Also, what would the syntax be in the configuration file?
MessageTemplateResourceName="My.Resources.ValidationStrings"?

Thanks again!
Aug 15, 2007 at 6:48 PM
Hi,

I see you have a VB.NET web application. I'm not sure how well this will work, as you may not know the name of the assembly where the resources reside; the configuration tool will certainly not help you here. Can you move your business logic code into a separate assembly?

The type name in this case is indeed Resources.ValidationStrings, but you cannot specify the assembly name. For attributes this is not an issue since you're referencing the actual type, but when you use configuration you need to specify a name that can be used to look up the type and this can be tricky for web apps.

Fernando
Aug 15, 2007 at 7:33 PM
I can move my business logic code into a separate assembly.

I currently have a web application and a class library that has my business objects in it.

Could I put the resx file inside here? where should it go? I don't think there is a App_GlobalResources directory for a class library. Is there anything that I would need to do to the resx file if I moved it to the class library (is it possible?)?

Thanks again.
curlypinhead
Aug 16, 2007 at 11:39 AM
Hi,

Resources can reside anywhere in your library projects. The "default" resources file, i.e. the one that is edited through the "Resources" tab in the project properties editor, is located under "My Project" for VB.NET (you have to "Show all files" to see it), but you can place it anywhere. Keep in mind that the name for the class generated from your resource file must match the full name of the resources file.

Regards,
Fernando