views:

1276

answers:

1

I am using a CMS tool to generate .resx resource files.

Is there any danger in creating resource names with spaces or punctuation characters in them?

If I use this syntax to get resources, it works fine:

GetGlobalResourceObject("myresources", "audio,visual");

However, this causes an error with declarative resource syntax, e.g.:

<asp:Literal ID="litLastName" runat="server" Text="<%$ Resources: GlobalResources,audio,visual %>"></asp:Literal>

Also, when I edit .resx files in Visual Studio, it gives me warnings if my resource keys contain any characters besides alphanumerics and underscores. It says "The resource name " is not a valid identifier".

Am I breaking a .NET rule here?

+3  A: 

The general guideline for resource keys are the same as the rules for a variable that you define.

Here is a comment in the asp.net forums stating that the use of a period is not allowed:

http://forums.asp.net/t/967741.aspx

Here is a question on SO about naming conventions for resx file key naming conventions:

http://stackoverflow.com/questions/896342/resource-resx-file-key-naming-conventions

Also, if you think about how they are used in the application having a key with a space or something odd is going to really hose the code as well. This is especially bad in the case of using a resource file for something like a telerik control as seen in this quick tutorial for a control:

http://www.telerik.com/help/aspnet-ajax/advancedmultilanguagelocal.html

If now you were adding a name there like

I like to put spaces in resource keys.ChartTitle.TextBlock.Text

Well, everything will barf all over the place because spaces mean something.

(It is also obvious in the above link why the period is no longer valid)

I suppose I could also punt and say, it seems that someone at Microsoft certainly thinks that's an error and that's why visual studio is giving you that error. Although, it is certainly good to question authority and the power of the man over us.

In the long run, there's probably not a reason why you would NEED to do something so unconventional.

Anthony Potts
Do you have a reference to back this up?
frankadelic