无法在VS Web解决方案中添加Resx文件

时间:2018-08-21 14:37:17

标签: c# asp.net .net resx

我第一次使用Resx文件。因此,按照以下步骤操作,直到现在为止。

  1. 创建了空的Asp.net解决方案。
  2. 添加了具有基本名称值内容的Resx文件。
  3. 添加一个网页,并在后面的代码中编写以下代码:

    protected void Page_Load(object sender, EventArgs e) { ResourceManager rm = new ResourceManager("UsingRESX.Resource1", Assembly.GetExecutingAssembly()); String strWebsite = rm.GetString("Website", CultureInfo.CurrentCulture); // here I get the exception String strName = rm.GetString("Name"); form1.InnerText = "Website: " + strWebsite + "--Name: " + strName; }

但是当我运行代码时,我得到了异常:

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

本练习遵循的教程: Read Resx FIle

我尝试过的

SO解决方案: SO Solution

enter image description here

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

尝试添加

var assembly = Assembly.GetExecutingAssembly();
assembly.GetManifestResourceNames();

并设置一个断点。这将列出所有嵌入式资源。确保您使用正确的名称。有时资源路径并不完全清楚。