WPF 从资源中获取字符串引发异常
WPF get string from resources throws an exception
我一直在尝试从资源文件中获取字符串:
var resourceManager = new ResourceManager(typeof(Properties.Settings));
var recent1 = resourceManager.GetString("recent1");
但是我遇到了一个例外:
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.
我该如何解决?
为了从 .resx 文件中检索字符串,不需要创建 ResourceManager
class 实例。在向资源添加字符串时,模板使用 internal static
签名作为 属性。因此可以直接获取资源:
var recent = Properties.Resources.recent1;
这是一个示例,当需要获取特定文化的资源时,如何通过创建 ResourceManager
的实例来获取字符串:
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");
有关其他信息,请参阅 ResourceManager.GetString Method。
我一直在尝试从资源文件中获取字符串:
var resourceManager = new ResourceManager(typeof(Properties.Settings));
var recent1 = resourceManager.GetString("recent1");
但是我遇到了一个例外:
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.
我该如何解决?
为了从 .resx 文件中检索字符串,不需要创建 ResourceManager
class 实例。在向资源添加字符串时,模板使用 internal static
签名作为 属性。因此可以直接获取资源:
var recent = Properties.Resources.recent1;
这是一个示例,当需要获取特定文化的资源时,如何通过创建 ResourceManager
的实例来获取字符串:
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");
有关其他信息,请参阅 ResourceManager.GetString Method。