This documentation is archived and is not being maintained.

StronglyTypedResourceBuilder.VerifyResourceName Method

Generates a valid resource string based on the specified input string and code provider.

Namespace:  System.Resources.Tools
Assembly:  System.Design (in System.Design.dll)

public static string VerifyResourceName(
	string key,
	CodeDomProvider provider


Type: System.String

The string to verify and, if necessary, convert to a valid resource name.

Type: System.CodeDom.Compiler.CodeDomProvider

A CodeDomProvider object that specifies the target language to use.

Return Value

Type: System.String
A valid resource name derived from the key parameter. Any invalid tokens are replaced with the underscore (_) character, or null if the derived string still contains invalid characters according to the language specified by the provider parameter.


key or provider is null.

If the key parameter is a valid string of characters, that string is returned. If the key parameter is an invalid string or a string that contains invalid characters, the VerifyResourceName method attempts to generate a valid string based on the key and provider parameters. If a valid string can be generated, that string is returned; otherwise, null is returned.

If the key parameter is an empty string (""), a string that consists of a single underscore character (_) is returned. If the key parameter is not an empty string, the VerifyResourceName method compares each character in the string to a set of invalid tokens based on the language specified by the provider parameter. Any invalid character in the string is replaced with an underscore character. The characters that will be replaced with an underscore are as follows:

' ' (space), U+00A0 (non-breaking space), '.' (period), ',' (comma), ';' (semicolon), '|', '~', '@', '#', '%', '^', '&', '*', '+', '-', '/', '\', '<', '>', '?', '[', ']', '(', ')', '{', '}', '"' (quote), ''' (apostrophe), ':', and '!'.


Strongly-typed resources do not allow the use of language keywords (such as if, for, and so on) as resource key names. However, the System.CodeDom design pattern allows the use of language keywords by prefixing the keyword with the underscore character. The VerifyResourceName method calls the CreateValidIdentifier method to enforce this design. For example, if you use a resource name that is the same as a language keyword, such as for, the name appears as _for in the generated strongly-typed resource class.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0