Problem with Resources

K

Ken Allen

OK, for a number of reasons I have needed to begin experimenting with
resources sooner than I had planned (I had avoided it for now).

Step 1: I built the 'reseditor' application that is in the SDK
sub-directory, as instructed by the MSDN.

Step 2: I used the 'reseditor' to create a file named
"MyResources.resources" that contains only some string resources.

Step 3: I added this resource file to my existing test assembly (does not do
anything other than test the use of the string resources to generate
altername 'names' for enumerated values).

Step 4: In the class definition (for my form since that is all there is in
this test code), I added "ResourceManager _Resources;".

Step 5: In the constructor for this form I added "_Resources = new
ResourceManager("MyResources", Assembly.GetExecutingAssembly());" (I
actually wrapped this in a try/catch block just in case, but the code does
not cause an exception).

Step 6: In my code I generate the name of the resource string I want and
attempt to retrieve it: "result.Append("[Retrieved] " +
_Resources.GetString(resourceName));" -- I have checked that the name I am
passing is the name of one of the strings in the resource file.

Step 7: I get a MissingManifestResourceException reporting that it "Could
not find any resources appropriate for the specified culture (or the neutral
culture) in the given assembly."

Step 8: This fails for any string I attempt to read.

Step 9: If I examine the binary of the resource file (which is in the
assembly), the contents indicate that it is for the neutral culture.

What am I doing wrong?

-Ken
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hello Ken,

Examine the assembly with the ILDASM tool to find out the real name of the
resource file. It will most likely be prefixed with the default namespace
name.
Therefore, on Step 5, you should specify the name of the resource file as:

"MyNamespace.MyResources"
 
K

Ken Allen

Hmmm. Using ILDASM I can see the file names in the manifest, but it is not
listed in the assembly itself -- at the top level I see MANIFESZT and
"EnumerationNaming" (the name of my assembly/solution), and inside
"EnumerationNameing" all I see is Form1 and the publuc enum "MyStates",
which are all that were defined in the Form1.cs file! In the manifest I see
these lines:

..mresource public EnumerationNaming.MyResources.resources
{
}
..mresource public EnumerationNaming.Form1.resources
{
}

I added the reopsurce file by copying the MyResources.resources file to the
same directory as the Form1.cs file and then performed an "Add Existing..."
function to add the file -- and it appears in the solution explorer!

I do not understand!

-Ken

Dmitriy Lapshin said:
Hello Ken,

Examine the assembly with the ILDASM tool to find out the real name of the
resource file. It will most likely be prefixed with the default namespace
name.
Therefore, on Step 5, you should specify the name of the resource file as:

"MyNamespace.MyResources"

Ken Allen said:
OK, for a number of reasons I have needed to begin experimenting with
resources sooner than I had planned (I had avoided it for now).

Step 1: I built the 'reseditor' application that is in the SDK
sub-directory, as instructed by the MSDN.

Step 2: I used the 'reseditor' to create a file named
"MyResources.resources" that contains only some string resources.

Step 3: I added this resource file to my existing test assembly (does
not
do
anything other than test the use of the string resources to generate
altername 'names' for enumerated values).

Step 4: In the class definition (for my form since that is all there is in
this test code), I added "ResourceManager _Resources;".

Step 5: In the constructor for this form I added "_Resources = new
ResourceManager("MyResources", Assembly.GetExecutingAssembly());" (I
actually wrapped this in a try/catch block just in case, but the code does
not cause an exception).

Step 6: In my code I generate the name of the resource string I want and
attempt to retrieve it: "result.Append("[Retrieved] " +
_Resources.GetString(resourceName));" -- I have checked that the name I am
passing is the name of one of the strings in the resource file.

Step 7: I get a MissingManifestResourceException reporting that it "Could
not find any resources appropriate for the specified culture (or the neutral
culture) in the given assembly."

Step 8: This fails for any string I attempt to read.

Step 9: If I examine the binary of the resource file (which is in the
assembly), the contents indicate that it is for the neutral culture.

What am I doing wrong?

-Ken
 
D

Dmitriy Lapshin [C# / .NET MVP]

.mresource public EnumerationNaming.MyResources.resources

This is the one you need. Therefore, you should change Step 5 to the
following:

_Resources = new ResourceManager("EnumerationNaming.MyResources",
Assembly.GetExecutingAssembly());

I really cannot explan why VS .NET appends the name of the namespace to the
name of the resource file itself,
it just works this way.


Ken Allen said:
Hmmm. Using ILDASM I can see the file names in the manifest, but it is not
listed in the assembly itself -- at the top level I see MANIFESZT and
"EnumerationNaming" (the name of my assembly/solution), and inside
"EnumerationNameing" all I see is Form1 and the publuc enum "MyStates",
which are all that were defined in the Form1.cs file! In the manifest I see
these lines:

.mresource public EnumerationNaming.MyResources.resources
{
}
.mresource public EnumerationNaming.Form1.resources
{
}

I added the reopsurce file by copying the MyResources.resources file to the
same directory as the Form1.cs file and then performed an "Add Existing..."
function to add the file -- and it appears in the solution explorer!

I do not understand!

-Ken

Dmitriy Lapshin said:
Hello Ken,

Examine the assembly with the ILDASM tool to find out the real name of the
resource file. It will most likely be prefixed with the default namespace
name.
Therefore, on Step 5, you should specify the name of the resource file as:

"MyNamespace.MyResources"

not
is
in
this test code), I added "ResourceManager _Resources;".

Step 5: In the constructor for this form I added "_Resources = new
ResourceManager("MyResources", Assembly.GetExecutingAssembly());" (I
actually wrapped this in a try/catch block just in case, but the code does
not cause an exception).

Step 6: In my code I generate the name of the resource string I want and
attempt to retrieve it: "result.Append("[Retrieved] " +
_Resources.GetString(resourceName));" -- I have checked that the name
I
 
K

Ken Allen

Yep, that did it. Basically this indicates that all of the MSDN examples are
wrong! One should use the following as the 'name' of the resource 'file'
that is embedded within the assembly:

_Resources = new
ResourceManager(Assembly.GetExceutingAssembly().GetName().Name +
".MyResources", Assembly.GetExecutingAssembly());

-Ken

Dmitriy Lapshin said:
.mresource public EnumerationNaming.MyResources.resources
{
}

This is the one you need. Therefore, you should change Step 5 to the
following:

_Resources = new ResourceManager("EnumerationNaming.MyResources",
Assembly.GetExecutingAssembly());

I really cannot explan why VS .NET appends the name of the namespace to the
name of the resource file itself,
it just works this way.


Ken Allen said:
Hmmm. Using ILDASM I can see the file names in the manifest, but it is not
listed in the assembly itself -- at the top level I see MANIFESZT and
"EnumerationNaming" (the name of my assembly/solution), and inside
"EnumerationNameing" all I see is Form1 and the publuc enum "MyStates",
which are all that were defined in the Form1.cs file! In the manifest I see
these lines:

.mresource public EnumerationNaming.MyResources.resources
{
}
.mresource public EnumerationNaming.Form1.resources
{
}

I added the reopsurce file by copying the MyResources.resources file to the
same directory as the Form1.cs file and then performed an "Add Existing..."
function to add the file -- and it appears in the solution explorer!

I do not understand!

-Ken

in message news:[email protected]...
Hello Ken,

Examine the assembly with the ILDASM tool to find out the real name of the
resource file. It will most likely be prefixed with the default namespace
name.
Therefore, on Step 5, you should specify the name of the resource file as:

"MyNamespace.MyResources"

OK, for a number of reasons I have needed to begin experimenting with
resources sooner than I had planned (I had avoided it for now).

Step 1: I built the 'reseditor' application that is in the SDK
sub-directory, as instructed by the MSDN.

Step 2: I used the 'reseditor' to create a file named
"MyResources.resources" that contains only some string resources.

Step 3: I added this resource file to my existing test assembly
(does
not
do
anything other than test the use of the string resources to generate
altername 'names' for enumerated values).

Step 4: In the class definition (for my form since that is all there
is
in
this test code), I added "ResourceManager _Resources;".

Step 5: In the constructor for this form I added "_Resources = new
ResourceManager("MyResources", Assembly.GetExecutingAssembly());" (I
actually wrapped this in a try/catch block just in case, but the
code
does
not cause an exception).

Step 6: In my code I generate the name of the resource string I want and
attempt to retrieve it: "result.Append("[Retrieved] " +
_Resources.GetString(resourceName));" -- I have checked that the
name
 
K

Ken Allen

As I noted, this resolved the problem, but now I am confused on how the
hierarchy of resource files work when one wishes to support more than one
language or dialect (e.g., culture). How do I use a single ResourceManage
that will search all cultures? Particularly, which constructor do I use? Do
I always reference the embedded resource file? Can I have more than one
embedded resource file? If so, how do I use them?

The information in MSDN is very sparse and, as I have discovered, very
misleading.

-Ken

Dmitriy Lapshin said:
.mresource public EnumerationNaming.MyResources.resources
{
}

This is the one you need. Therefore, you should change Step 5 to the
following:

_Resources = new ResourceManager("EnumerationNaming.MyResources",
Assembly.GetExecutingAssembly());

I really cannot explan why VS .NET appends the name of the namespace to the
name of the resource file itself,
it just works this way.


Ken Allen said:
Hmmm. Using ILDASM I can see the file names in the manifest, but it is not
listed in the assembly itself -- at the top level I see MANIFESZT and
"EnumerationNaming" (the name of my assembly/solution), and inside
"EnumerationNameing" all I see is Form1 and the publuc enum "MyStates",
which are all that were defined in the Form1.cs file! In the manifest I see
these lines:

.mresource public EnumerationNaming.MyResources.resources
{
}
.mresource public EnumerationNaming.Form1.resources
{
}

I added the reopsurce file by copying the MyResources.resources file to the
same directory as the Form1.cs file and then performed an "Add Existing..."
function to add the file -- and it appears in the solution explorer!

I do not understand!

-Ken

in message news:[email protected]...
Hello Ken,

Examine the assembly with the ILDASM tool to find out the real name of the
resource file. It will most likely be prefixed with the default namespace
name.
Therefore, on Step 5, you should specify the name of the resource file as:

"MyNamespace.MyResources"

OK, for a number of reasons I have needed to begin experimenting with
resources sooner than I had planned (I had avoided it for now).

Step 1: I built the 'reseditor' application that is in the SDK
sub-directory, as instructed by the MSDN.

Step 2: I used the 'reseditor' to create a file named
"MyResources.resources" that contains only some string resources.

Step 3: I added this resource file to my existing test assembly
(does
not
do
anything other than test the use of the string resources to generate
altername 'names' for enumerated values).

Step 4: In the class definition (for my form since that is all there
is
in
this test code), I added "ResourceManager _Resources;".

Step 5: In the constructor for this form I added "_Resources = new
ResourceManager("MyResources", Assembly.GetExecutingAssembly());" (I
actually wrapped this in a try/catch block just in case, but the
code
does
not cause an exception).

Step 6: In my code I generate the name of the resource string I want and
attempt to retrieve it: "result.Append("[Retrieved] " +
_Resources.GetString(resourceName));" -- I have checked that the
name
 
D

Dmitriy Lapshin [C# / .NET MVP]

Ken,

I would disagree. The MSDN docs on satellite assemblies and resource
fallback process are pretty consistent.
Take a look at the following:

http://msdn.microsoft.com/library/d...ide/html/cpconcreatingsatelliteassemblies.asp
http://www.ondotnet.com/pub/a/dotnet/2002/10/14/local2.htm
http://msdn.microsoft.com/library/d...ntroduction_to_resources_and_localization.asp
http://msdn.microsoft.com/library/d...-us/cpguide/html/cpconlocalizingresources.asp


Ken Allen said:
As I noted, this resolved the problem, but now I am confused on how the
hierarchy of resource files work when one wishes to support more than one
language or dialect (e.g., culture). How do I use a single ResourceManage
that will search all cultures? Particularly, which constructor do I use? Do
I always reference the embedded resource file? Can I have more than one
embedded resource file? If so, how do I use them?

The information in MSDN is very sparse and, as I have discovered, very
misleading.

-Ken

Dmitriy Lapshin said:
.mresource public EnumerationNaming.MyResources.resources
{
}

This is the one you need. Therefore, you should change Step 5 to the
following:

_Resources = new ResourceManager("EnumerationNaming.MyResources",
Assembly.GetExecutingAssembly());

I really cannot explan why VS .NET appends the name of the namespace to the
name of the resource file itself,
it just works this way.


Ken Allen said:
Hmmm. Using ILDASM I can see the file names in the manifest, but it is not
listed in the assembly itself -- at the top level I see MANIFESZT and
"EnumerationNaming" (the name of my assembly/solution), and inside
"EnumerationNameing" all I see is Form1 and the publuc enum "MyStates",
which are all that were defined in the Form1.cs file! In the manifest
I
see
these lines:

.mresource public EnumerationNaming.MyResources.resources
{
}
.mresource public EnumerationNaming.Form1.resources
{
}

I added the reopsurce file by copying the MyResources.resources file
to
the
same directory as the Form1.cs file and then performed an "Add Existing..."
function to add the file -- and it appears in the solution explorer!

I do not understand!

-Ken

in message Hello Ken,

Examine the assembly with the ILDASM tool to find out the real name
of
the
resource file. It will most likely be prefixed with the default namespace
name.
Therefore, on Step 5, you should specify the name of the resource
file
as:
"MyNamespace.MyResources"

OK, for a number of reasons I have needed to begin experimenting with
resources sooner than I had planned (I had avoided it for now).

Step 1: I built the 'reseditor' application that is in the SDK
sub-directory, as instructed by the MSDN.

Step 2: I used the 'reseditor' to create a file named
"MyResources.resources" that contains only some string resources.

Step 3: I added this resource file to my existing test assembly (does
not
do
anything other than test the use of the string resources to generate
altername 'names' for enumerated values).

Step 4: In the class definition (for my form since that is all
there
is
in
this test code), I added "ResourceManager _Resources;".

Step 5: In the constructor for this form I added "_Resources = new
ResourceManager("MyResources", Assembly.GetExecutingAssembly());" (I
actually wrapped this in a try/catch block just in case, but the code
does
not cause an exception).

Step 6: In my code I generate the name of the resource string I
want
and
attempt to retrieve it: "result.Append("[Retrieved] " +
_Resources.GetString(resourceName));" -- I have checked that the
name
I
am
passing is the name of one of the strings in the resource file.

Step 7: I get a MissingManifestResourceException reporting that it
"Could
not find any resources appropriate for the specified culture (or the
neutral
culture) in the given assembly."

Step 8: This fails for any string I attempt to read.

Step 9: If I examine the binary of the resource file (which is in the
assembly), the contents indicate that it is for the neutral culture.

What am I doing wrong?

-Ken
 
K

Ken Allen

Perhaps the online MSDN is more accurate. I must confess that I have
depended mostly on the installed MSDN information since I cannot always
access the internet during development. The installed MSDN is terrible for
inaccuracies as these items are not as clearly addressed there.

-Ken

Dmitriy Lapshin said:
Ken,

I would disagree. The MSDN docs on satellite assemblies and resource
fallback process are pretty consistent.
Take a look at the following:

http://msdn.microsoft.com/library/d...ide/html/cpconcreatingsatelliteassemblies.asp
http://msdn.microsoft.com/library/d...-us/cpguide/html/cpconlocalizingresources.asp


Ken Allen said:
As I noted, this resolved the problem, but now I am confused on how the
hierarchy of resource files work when one wishes to support more than one
language or dialect (e.g., culture). How do I use a single ResourceManage
that will search all cultures? Particularly, which constructor do I use? Do
I always reference the embedded resource file? Can I have more than one
embedded resource file? If so, how do I use them?

The information in MSDN is very sparse and, as I have discovered, very
misleading.

-Ken

in message news:[email protected]... to
the is
not
manifest
name
Assembly.GetExecutingAssembly());"
(I
actually wrapped this in a try/catch block just in case, but the code
does
not cause an exception).

Step 6: In my code I generate the name of the resource string I want
and
attempt to retrieve it: "result.Append("[Retrieved] " +
_Resources.GetString(resourceName));" -- I have checked that the name
I
am
passing is the name of one of the strings in the resource file.

Step 7: I get a MissingManifestResourceException reporting that it
"Could
not find any resources appropriate for the specified culture (or the
neutral
culture) in the given assembly."

Step 8: This fails for any string I attempt to read.

Step 9: If I examine the binary of the resource file (which is
in
the
assembly), the contents indicate that it is for the neutral culture.

What am I doing wrong?

-Ken
 

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