关于“MissingManifestResourceException was unhandled”错误

做一个关于“Creating a satellite assembly for culture specific resource file and using it in the executing assembly”的练习

添加了resources 文件之后 并在其中添加Name(Key) 、value

注:在以****.resx命名的resources文件中label1.Text不起作用(原因不明)

 

在Visual Studio .NET 命令提示框窗口中打入“Resgen MyResource.zh-CN.resx”生成MyResource.zh-CN.resources的二进制文件
通过在命令行窗口添加一下代码生成MyApplication.resources.dll文件

Al /t:lib /embed:D:\Exercise3\Exercise\MyApplication\MyResource.zh-CN.resources,MyApplication.MyResource.zh-CN.resources /culture:zh-CN /out:D:\Exercise3\Exercise\MyApplication\bin\zh-CN\MyApplication.resources.dll

在添加Button_click方法:

ExpandedBlockStart.gif 代码
1    private   void  button1_Click( object  sender, EventArgs e)
2   {
3           messageId  =  label1.Text;
4           CultureInfo ci  =   new  CultureInfo( " zh-CN " );
5           ResourceManager resmgr  =   new  ResourceManager( " MyResource.zh-CN " , Assembly.GetExecutingAssembly());
6           label1.Text  =  resmgr.GetString(messageId, ci);
7   }

 

 

可是运行到第六行就报错:MissingManifestResourceException was unhandled
Could not find any resources appropriate for the specified culture or the neutral culture.
Make sure "MyResource.zh-CN.resources" was correctly embedded or linked into assembly "MyApplication" at compile time, or that all the satellite assemblies required are loadable and fully signed.

出错的原因:

ResourceManager("MyResource.zh-CN", Assembly.GetExecutingAssembly());中的第一个参数应该为Project名+resource 的文件名

应该改成:“Project名.resource 文件名”

ExpandedBlockStart.gif 代码
1           private   void  button1_Click( object  sender, EventArgs e)
2          {
3               string   messageId  =  label1.Text;
4              CultureInfo ci  =   new  CultureInfo( " zh-CN " );
5              ResourceManager resmgr  =   new  ResourceManager( " MyApplication.MyResource_zh " , Assembly.GetExecutingAssembly());
6               string  msg  =  resmgr.GetString(messageId, ci);
7              label1.Text  =  msg;
8 
9          }

 


 

可是还是不成功,于是我重建一个resource文件,以MyResource_zh为名,发现系统自动在资源文件下添加了一个.cs文件

其中有需要lookup的字段:

ExpandedBlockStart.gif 代码
///   <summary>
///    Looks up a localized string similar to Chinese.
///   </summary>
internal   static   string  中文 {
  
get  {
          
return  ResourceManager.GetString( " 中文 " , resourceCulture);
      }
}

 

 正确添加name与value之后,程序正确运行

 

注:

1、以*****.特定区域属性(如:en-US、zh-CN)命名的resource文件不会生成.cs文件(原因不详)

2、资源文件中所填的Name 和 Vale为程序中所要翻译的源和目标结果

 

转载于:https://www.cnblogs.com/xuyinjie/articles/1691623.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值