中国开发网: 论坛: .NET/C#: 贴子 110736
heavenround
问个资源引入的问题。
资源文件:Greating.resource
里面只存了一个键一个值:greating="hello,world!"

测试文件:ResourceDemo.cs 应用程序

namespace ResourceDemo
{
using System.Resource;
using System.Reflection;

//...其它的声名

private ResourceManager resM;

public Form1()
{

//...

InitializeComponent();

Assembly assembly=Assembly.GetExecutingAssembly();
resM=new ResourceManager("ResourceDemo.Greating",assembly);
textBoxGreating=resM.GetString("greating"); //textBoxGreating 是一个TextBox

//...其它

}

资源文件用VS。NET 加入,且在属性中设为“嵌入的资源“,不知道为什么一运行就出现如下异常:

未处理的“System.Resources.MissingManifestResourceException”类型的异常出现在 mscorlib.dll 中

其他信息:未能在给定的程序集中找到任何适合于指定的区域性(或非特定区域性)的资源。请确保已将“ResourceDemo.Greating.resources”正确嵌入或链接到程序集“ResourceDemo”。
baseName: ResourceDemo.Greating.resource locationInfo: <null> resource file name: ResourceDemo.Greating.resources assembly:


声名ResourceManager第一个参数是“名称空间+资源文件名(无扩展名)“,第二个是要引入的装配件。
名称空间是这个正在运行程序的,文件名也没错,不知道为什么无法引入?

用VS。NET自带的.RESX模版生成的资源文件就可以成功引入,不知道为什么用ResourceWriter写的就不行

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录