1

I'm working on a localized application which I develop in SharpDevelop. Based on a tutorial I ran into an error:

Could not find any resources appropriate for the specified culture (or the neutral culture) on disk. baseName:

I created the ressource file using Project | Add | New item respective "Empty ressource file" (I couldn't find "Assembly Resource file"). Furthermore I've set the "Build action" to "EmbeddedResource".

Within the program I have a class which does the following

// load the resource file once
resourceManager = ResourceManager.CreateFileBasedResourceManager(file, filePath, null);

// depending on user selection, I set the CultureInfo in the code behind the form, i.e.
Thread.CurrentThread.CurrentUICulture = locales[0];   // which contains "en"

// and that's the method of the same class used to lookup the values
public string getValue ( string key )
{
    return resourceManager.GetString(key);
}

SharpDevelop 3.0.0.3437 .NET Version 2.0.50727.3053

Even after carefully going through the comments and googling for a long while, I couldn't find an example or a solution. Hence the questions:

  • How can I add the culture to the ressource file itself?
  • Can you provide an example or link?

Many thanks!

2 Answers 2

1

CreateFileBasedResourceManager will only deal with binary .resources files (not .resx files).

If you insist on loading resources from external file rather than embed the resources into the assembly, you will need to run the resgen command line utility to generate a .resources file. So if you haven't done that, generate one for each supported culture.

Otherwise it looks OK.

But if you would rather embed resources into assembly, in the properties window, set the Build Action to Embedded Resource.

If you want also want a strongly typed class generated taking care of all the dirty work, set the Custom Tool on the base file only (the invariant one) to ResXFileCodeGenerator, or PublicResXFileCodeGenerator if you need that (good when creating satellite assemblies).

Then you don't need to take care of loading the localized resources yourself. The generated class does all this for you.

For each key in the resource, a static property is generated in the generated class, and you'll just invoke this property, it is very clean and by far the easiest way.

Unless there are special reasons for loading resources from .resources files, i would always recommend embedding them into the (an) assembly.

0

I'm not sure what version of .NET you are using but this MSDN article on how the runtime locates assemblies may be of service to you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.