If you have tried to localize Silverlight applications using .resx files you will probably have noticed that strongly typed resource classes don't work straight out of the box. This post describes how you can overcome this.
New in Visual Studio 2008 is the PublicResXFileCodeGenerator, a code generator for creating public strongly typed resource classes. This code generator does indeed generate public classes with public properties and for all applications except Silverlight this is exactly what is wanted of a public strongly typed resource class. But for Silverlight applications it is not enough. The problem is that the constructor in the generated code is still internal. Normally this doesn't make any difference because nothing ever constructs a strongly typed resource class directly; only the static properties are used. But the constructor is used in a Silverlight application and that's where the internal constructor is unhelpful. The manual solution to this problem is to edit the generated code and this is a very undesirable solution because you have to continually re-edit the generated code every time it is re-generated. A more permanent solution is needed and it is available in the form of the PublicResourceCodeGenerator. I have written a number of code generators for strongly typed resource classes that solve various problems. You can download the code generators here and the source code is included in the source code for my .NET Internationalization book here. Here is the current list of code generators for strongly typed resource classes:-
|Code Generator Class
||Generates the exact same code as the ResXFileCodeGenerator and offers no additional benefit.
||Generates almost the same code as the PublicResXFileCodeGenerator except that the constructor is public instead of internal.
||Generates the same code as the ResXFileCodeGenerator except that it uses a provider model instead of the ResourceManager.
||Generates the same code as the PublicResXFileCodeGenerator except that it uses a provider model instead of the ResourceManager and the constructor is public.
||Generates the same code as the GlobalResXFileProxyGenerator (used for ASP.NET global resources) except that it uses a provider model instead of the ResourceManager.
So to generate strongly typed resource classes that can be used in Silverlight applications select the .resx file in Solution Explorer and then in the Properties Window set the Custom Tool to PublicResourceCodeGenerator.