Search code examples
.netvisual-studiovisual-studio-2010embedded-resource

Suppress "The resource name is not a valid identifier"


I have a project with 5000+ resource strings in it. Almost all of them have periods in their identifier.

We're switching over to automatically generating strongly-typed classes, and of course, because of the periods, we see a few thousand warnings

The resource name 'blah' is not a valid identifier.

I know it isn't, the generator changes periods to underscores, and everything is fine.

Can I suppress the warning? It doesn't seem to have an associated number to #pragma away.


Solution

  • I think I can repro, although it isn't crystal in the question. Project + Properties, Resources and type a string resource name like "foo.bar" triggers this warning.

    Yes, you cannot suppress this warning, it is generated by the resource designer in the IDE. When it auto-generates the code from the Properties\Resources.resx file to the Properties\Resources.Designer.cs file. Look at the .resx file and check the "name" attribute on the <data> elements. A period in the attribute value is going to trigger the warning.

    A carefully crafted search-and-replace with regexp could fix that by turning the periods into underscores. That gives me personally two problems, I'd just write a little program that uses XDocument. Also check if you still need this auto-generated code, sounds like you are replacing it.