c# - 无法在 VS Web 解决方案中添加 Resx 文件
问题描述
我第一次使用 Resx 文件。所以下面的步骤我到现在为止。
- 创建了空的 Asp.net 解决方案。
- 添加了具有基本名称值内容的 Resx 文件。
添加一个网页,并在后面的代码中写下以下代码:
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 解决方案
解决方案
尝试添加
var assembly = Assembly.GetExecutingAssembly();
assembly.GetManifestResourceNames();
并设置断点。这将列出所有嵌入的资源。确保您有正确的名称。有时资源路径并不完全明显。
推荐阅读
- python - collections.abc.Callable 在 Python 3.9.1 中是否存在错误?
- javascript - 为什么 exitFullscreen 的这种特定情况不起作用?
- javascript - wp_localize_script 功能不工作:遵循类似的问题解决方案
- xml - Android 调试器显示 xml 文件有问题,但我找不到
- sql-server - 我的简单 sqlxml 查询有什么问题?
- python - 如何解决“未定义名称'bot'”错误?
- flutter - Flutter - 列内的 TabBar
- flutter - Flutter 通知面板
- wordpress - WooCommerce / PDF 发票 / 将税率四舍五入到小数点后一位
- python-3.x - 简单的方格查找