How to resolve this "Resource name is not a valid identifier" compiler warning
Strongly typed means that a variable, field, or property is of a specific type instead of just Object
.
public class User
{
public String FirstName { get; set; } // Strongly typed
public Object LastName { get; set; } // Weakly typed
}
If you use strongly typed resources, code is generated with strongly typed properties for all your resources. In this case the resource name is used as the property name, hence it must be a valid C# property name. Your example MB_ArchiveRestore.cs_11
contains a dot and is in consequence not a valid property name. The code generator will replace the dot with an underscore to make the name valid and gives you the described warning to inform you about that.
The problem occurs because .
is not a valid character in identifiers.
What does strongly typed exactly mean?
Although it's not as relevant for this particular question, "strongly typed" means that an object has a definite notion of type. For example, you can't do int i = "5";
in C#, because "5" is a string and i
is an integer -- their types are incompatible with each other.
This is contrast to "weakly typed" languages, where the notion of "type" is not as strong. A weakly typed language might decide that for something like i = 5; j = "6"; print (i + j);
, the correct response is 11.
Based on the link you have posted in the question, I think that you are probably asking about strongly typed resource generation
- that means that Visual Studio will generate a resources file which will allow you to access resources via typed properties, e.g.
string fileName = Resources.FileName;
bool someSetting = Resources.AllowDelete;
byte[] binaryResource = Resources.SomeFile;
as opposed to untyped resources where you have to cast the return value by yourself because it returns type System.Object instead of a specific type.
string fileName = (string)Resources["FileName"];
bool someSetting = (bool)Resources["AllowDelete"];
byte[] binaryResource = (byte[])Resources["SomeFile"]