首页 > 解决方案 > 无法在 VS Web 解决方案中添加 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.

我在本练习中遵循的教程: 阅读 Resx 文件

我尝试过的 SO 解决方案: SO 解决方案

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

标签: c#asp.net.netresx

解决方案


尝试添加

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

并设置断点。这将列出所有嵌入的资源。确保您有正确的名称。有时资源路径并不完全明显。


推荐阅读