如何加载资源 [英] How to load resource

查看:100
本文介绍了如何加载资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目资源文件* .resx中添加并尝试循环所有字段:



I added at project resource file *.resx and try get at loop all fields:

ResourceManager r = new ResourceManager("GridColumnsNames", System.Reflection.Assembly.GetExecutingAssembly());



但是得到错误:

无法找到适合指定文化或中性文化的任何资源。确保在编译时将GridColumnsNames.resources正确嵌入或链接到程序集Cards中,或者所有所需的附属程序集都是可加载和完全签名的。





可能我必须指出资源的全球路径?现在它位于文件Form1.cs


But get error:
Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "GridColumnsNames.resources" was correctly embedded or linked into assembly "Cards" at compile time, or that all the satellite assemblies required are loadable and fully signed.


May be i must point global path to resource? Now it lay at directory where is file Form1.cs

推荐答案

的目录下看看你的资源键,很可能你错了。格式为:Namespace.path.resourcekey。



示例:

如果您的资源名为 GridColumnsNames ,然后将它放在项目名称 MyNamespace 中项目的 MyResources 文件夹中。路径将是

MyNamespace.MyResources.GridColumnsNames



可能还有其他错误来源:



*检查您是否将资源文件的构建操作设置为嵌入式资源

*检查您是否使用了正确的程序集(当调用 GetExecutingAssembly 时)

*检查您是否提供了至少一个中性资源或指定与该文化的现有资源文件对应的程序集的中性语言。
Have a look at your resource-key, most likely you got that wrong. The Format is: Namespace.path.resourcekey.

Example:
If your resource is named GridColumnsNames, and you put it in a folder MyResources in your Project within a namespace MyNamespace. The path would be
MyNamespace.MyResources.GridColumnsNames

There could be other error sources:

* Check if you set the build-action for the resource file to Embedded Resource
* Check if you are using the correct assembly (when calling GetExecutingAssembly)
* Check if you provided at least a neutral resource or specified the neutral language of the assembly corresponding to an existing resource file for that culture.


这篇关于如何加载资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆