Resgen /str - Issue generating C# resource wrapper classes.

A

Andy B

Hi All,

There seems to be a "feature" when using the resgen /str option to generate
C# wrapper classes for the resource.

The generated code which links the resource manage to the resource does not
specify the resgen output file but instead forms the resource name from the
supplied namespace and class name.

eg
global::System.Resources.ResourceManager temp = new
global::System.Resources.ResourceManager("<Specified namespace and wrapper
class name here>", typeof( AccountExternalEditModule).Assembly);

Surely it should reference the generated resgen output file.

Regards

Andy B
 
S

Steven Cheng[MSFT]

Hello Andy,

Yes, you're right, the resgen generated wrapper class should locate the
resource based on its output file name rather than the
"Namespace+ClassName". And currently the generated wrapper class will
always use the below style code by default:

==================
global::System.Resources.ResourceManager temp = new
global::System.Resources.ResourceManager("<Specified namespace and wrapper
class name here>", typeof( AccountExternalEditModule).Assembly);
==================

which assume that our output resource file name is identical to the
"Namespace+ClassName"(the recommended approach since this can help better
understand the resource). And if we choose to use different name for the
output resource file and the "Namespace+ClassName", the resgen tool will
output the some warning indicate that the output resource file name is
different from the Wrapper class's "namespace+classname", and we need to
change filename if if we want to make the generated code work correctly.
e.g.

suppose we execute the following command:

resgen strings.txt Mystrings.resources /publicClass
/str:C#,TestNS,StringsWrapperClass,StringsClass.cs

the commandline will output the below warning

============================
Writing resource file... Done.
Creating strongly typed resource class "TestNS.StringsWrapperClass"...
strings.txt : warning RG0000: The base name of your output file,
"Mystrings", do
es not match the base name used by the strongly typed resources,
"TestNS.Strings
WrapperClass". In order for the strongly typed resources to work
correctly, you
will need to rename your output file to
"TestNS.StringsWrapperClass.resources".
============================

So we need to modify the generated wrapper class code as below:

================
global::System.Resources.ResourceManager temp = new
global::System.Resources.ResourceManager("{ProjectNameSpace}.Mystrings",
typeof(StringsWrapperClass).Assembly);
================

The {ProjectNamespace} here is necessary when we embeded the output
resource file in a certain project which has the project namespace(will be
inserted before the resource file name when compiled into assembly).

Hope this helps & Thanks for your posting.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top