views:

709

answers:

7

I've got a bunch of Warnings in a Visual Studio 2005 project, most of them are warning me that a resource name is not a valid identifier.

example:

The resource name 'MB_ArchiveRestore.cs_11' is not a valid identifier.

MSDN online help indicates that the resource name needs to be strongly typed, and not contain spaces. What does strongly typed exactly mean?

A: 

I'm not sure if it will help you fix your problem but in the interest of answering your actual question. Strongly typed means that the the variable is of a given type, as opposed to some type determined at run time. Check out Wikipedia

For example:

Int32 counter;

Means the counter variable is strongly typed, as we know it is an Int32. Other languages or use of dynamic keywords mean:

dynamic counter = ResultOfFunc()

means that counter is not strongly typed, as it is determined at run time by the result of the ResultOfFunc().

Ian
+2  A: 

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.

John Feminella
+1 if i remove the . the warning goes away
Kevin
+6  A: 

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"]
Marek
A: 

I would have to guess that it's complaining about the _11 at the end, which would make it not a valid C# file, thus, not a valid resource.

Slokun
The _11 would not make it an invalid file
Rune FS
A: 

"Strongly Typed" in this case, means that Visual Studio is trying to generate an object model for you to use, from your resource names.

For example, say you have a resource file with URLs that point to your favorite websites. your resources are something like:

when the resource generate is used to strongly type this, you will end up with an object model that can be called like this:

string googleUrl = Resources.Google; string msUrl = Resources.Microsoft;

when you have a period in the name of the resource, the code generator cannot use it because it would create invalid names in the Resources object. for exmaple:

this would be invalid because it would try to create a resource named Resources.Asp.NET

Derick Bailey
+3  A: 

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.

Daniel Brückner
A: 

I guess that you have a resource named "MB ArchiveRestore.cs 11". Since VS 2005 the compiler (or more precisely an add-on tool) will automatically generate access classes for embedded resources. These can be used to retrieve the resources. The class property for your example is probably Properties.Resources.MB_ArchiveRestore.cs_11. These stronlgy typed resource classes also provide a convenient way for localization.

rotti2