loading strings

P

Phil Da Lick!

Hello,

Got strings.resx included in my assmebly as the default language neutral
collection.

ResourceManager res=new ResourceManager("strings",
Assembly.GetExecutingAssembly());

string test=res.GetString("TestString");

TestString exists in the resource file. The compiler message window
seems to indicate thsat the strings are compiled and included in the
assembly but I'm getting unhandled exception
System.Resources.MissingManifestResourceException

Could not find any resources appropriate for the specified culture in
the given assembly. Make sure "strings.resources" was correctly linked
or embedded into assembly.

Help!!!
 
K

Kai Brinkmann [MSFT]

You need to use the fully qualified name of the resource file in the
ResourceManager constructor.
--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Phil Da Lick!

Kai said:
You need to use the fully qualified name of the resource file in the
ResourceManager constructor.

what resource file? does it not work the same way as VC++ where the
resources are compiled into the assembly? I've just added the resources
in a resx to the assembly in the prroject view.
 
K

Kai Brinkmann [MSFT]

Yes, the base resources are compiled into the assembly. All language
resource files end up in satellite assemblies. If you're using VS, this will
be done automatically as long as you observe the proper naming conventions.

For example, let's assume you created a resource file AppResources.resx in
your project and your namespace is MyNamespace.MyApp.
In this case, the ctor for your ResourceManager should look like this:

ResourceManager rm = new ResourceManager("MyNamespace.MyApp.AppResources",
Assembly.GetExecutingAssembly());

Note the fully qualified resource name!

AppResources.resx is compiled to AppResources.resources (you can do this
manually using resgen) and embedded in your core assembly (MyApp.exe). You
can create localized resource files like this:

AppResources.fr-FR.resx // French (France) resources
AppResources.de-DE.resx // German (Germany) resources
AppResources.ja-JP.resx // Japanese (Japan) resources

These resources will also be compiled to their appropriate resources files
and embedded in satellite assemblies named MyApp.resources.dll. These
assemblies will end up in directories named after the culture (fr-FR, de-DE,
ja-JP) underneath your main application directory. At run-time, the resource
manager will attempt to find appropriate resources for the selected
CurrentUICulture. There is a fallback mechanism if no resources can be
found, and as a last resort the resources embedded in the main assembly will
be used (i.e. the resources in the base resource file AppResources.resx).

I hope this helps.
--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Phil Da Lick!

Kai said:
Yes, the base resources are compiled into the assembly. All language
resource files end up in satellite assemblies. If you're using VS, this will
be done automatically as long as you observe the proper naming conventions.

For example, let's assume you created a resource file AppResources.resx in
your project and your namespace is MyNamespace.MyApp.
In this case, the ctor for your ResourceManager should look like this:

ResourceManager rm = new ResourceManager("MyNamespace.MyApp.AppResources",
Assembly.GetExecutingAssembly());

Note the fully qualified resource name!

Just what I needed, thanks.

AppResources.resx is compiled to AppResources.resources (you can do this
manually using resgen) and embedded in your core assembly (MyApp.exe). You
can create localized resource files like this:

AppResources.fr-FR.resx // French (France) resources
AppResources.de-DE.resx // German (Germany) resources
AppResources.ja-JP.resx // Japanese (Japan) resources

So can I also just include these into the assembly in the project view
and VS will take care of them automatically?
 

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