问题描述
我需要能够在运行时加载资源,并已在一个简单的C#测试应用程序中使用以下代码:-
ResourceManager rm =新的ResourceManager("ResourceTest.Resources",this.GetType().Assembly);
字符串someString = rm.GetString("MyString");
label1.Text = someString;
当我尝试运行应用程序时,第二行代码对GetString()的调用将引发MissingManifestResourceException.
但是,如果我通过在解决方案资源管理器中右键单击项目节点并选择添加" |添加",将新的资源"文件添加到项目中.新商品|资源文件我得到一个默认为Resource1.resx的新res文件.然后,我可以在上面的代码中引用该文件(将ResourceManager构造函数中的第一个参数更改为"ResourceTest.Resource1"),并且一切正常.
项目中的默认资源文件为什么不起作用,但是我添加的任何资源文件都会起作用?
顺便说一句,如果有任何区别,我正在使用Visual Studio 2005 ??
谢谢
Alan
I need to be able to load resources at runtime and have used the following code in a simple C# test app :-
ResourceManager rm = new ResourceManager("ResourceTest.Resources", this.GetType().Assembly);
string someString = rm.GetString("MyString");
label1.Text = someString;
When I try to run the app, the call to GetString() on the second line of code throws a MissingManifestResourceException.
However, if I add a new Resource file to the project by right clicking the project node in the Solution Explorer and select Add | New Item | Resource File I get a new res file called, by default, Resource1.resx. I can then reference this file in the above code (changing the first param in the ResourceManager contructor to "ResourceTest.Resource1") and all works fine.
How come the default Resource file in the project won''t work but any resource file I add will ?
BTW, I am using Visual Studio 2005 if it makes any difference ??
Thanks
Alan
推荐答案
这篇关于在运行时加载资源时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!