abdulmalik Tech Geek
abdulmalik Tech Geek

Reputation: 15

WPF get string from resources throws an exception

I've been trying to get a string from resources file:

var resourceManager = new ResourceManager(typeof(Properties.Settings));
var recent1 = resourceManager.GetString("recent1");

But I got an exception:

System.Resources.MissingManifestResourceException: 'Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "ProCodeX.Properties.Settings.resources" was correctly embedded or linked into assembly "ProCodeX" at compile time, or that all the satellite assemblies required are loadable and fully signed.

How do I fix it?

Upvotes: 1

Views: 578

Answers (1)

Victor
Victor

Reputation: 8985

For retrieve string from .resx file don't no need to create the ResourceManager class instance. The template uses internal static signature for the property when adding a string to the resources. Therefore the resource can be obtained directly:

var recent = Properties.Resources.recent1; 

And here's an example how do get the string by creating instance of the ResourceManager when required to obtain resource for specific culture:

ResourceManager rm = new ResourceManager("WpfApp11.Properties.Resources", typeof(Properties.Resources).Assembly);
CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
var recent1 = rm.GetString("recent1");

For additional information see ResourceManager.GetString Method.

Upvotes: 3

Related Questions