Winform程序想把几个图片打包进资源文件使用,但是总是出错;
错误提示如下:
未能找到任何适合于指定的区域性或非特定区域性的资源。请确保在编译时已将“useStrRes.mystr.resources”正确嵌入或链接到程序集“useStrRes”,或者确保所有需要的附属程序集都可加载并已进行了完全签名。
在网上差到一些例子,都说把命名空间设置以后就可以了,我设置了可是还不行,于是就把SDK中的例子拿来测试一把,是字符串资源的创建和使用,结果又出同样的错误。
程序如下:
资源的创建:
namespace stringRes
{
    public partial class Form1 : Form
    {
        public ResourceWriter rw;
        public Form1()
        {
            InitializeComponent();
        }        private void button1_Click(object sender, EventArgs e)
        {
            rw = new ResourceWriter("mystr.resources");
            rw.AddResource("String 1", "First String");            rw.AddResource("String 2", "Second String");            rw.AddResource("String 3", "Third String");
            rw.Generate();
            rw.Close();
            label1.Text = "创建资源成功";        }
    }
}创建后把资源加入到另一个工程中,一个Button按钮读取资源,然后分别赋值给三个Label:
namespace useStrRes
{
    public partial class Form1 : Form
    {
        public ResourceManager rm = new ResourceManager("useStrRes.mystr",Assembly.GetExecutingAssembly());
        public Form1()
        {
            InitializeComponent();
        }        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                label1.Text = ((string)rm.GetString("String 1"));            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}