我有两个ASP。NET Web项目(ProjectA和projecb)。当ProjectA中的类正在实例化ProjectB中的一个类时,它使用了一个资源文件Blah。resx,我得到这个错误:

一个System.Resources类型的异常。mscorlib.dll中出现了MissingManifestResourceException',但在用户代码中没有处理。 无法找到适用于指定区域性或中性区域性的任何资源。确保“资源。等等。”资源“正确嵌入或链接到程序集”App_GlobalResources。Sn_flri6”,或者所有所需的附属程序集都是可加载的并具有全符号。

是什么导致的?

在微软的网站上有一篇关于http://support.microsoft.com/kb/318603的文章,它建议:

要解决此问题,请移动所有其他类定义,使它们出现在表单的类定义之后。

这是一个Windows窗体项目的解决方案,我不确定这是否也适用于Web项目。


当前回答

这是因为*。res不包含在迁移中。

右键单击资源文件 点击菜单项“Include in project”

其他回答

对于在。net Core 3.0中遇到这个问题的用户,这可能与。net Core 3.0中的一个破坏性更改有关,要解决这个问题,只需在项目csproj中将EmbeddedResourceUseDependentUponConvention设置为false:

<PropertyGroup>
  <EmbeddedResourceUseDependentUponConvention>true</EmbeddedResourceUseDependentUponConvention>
</PropertyGroup>

我是这样解决的:

右键点击资源文件,然后选择属性 将“Build Action”属性编译为“Embedded Resource” 然后构建并运行

它工作得很完美。

我有一个WinForms应用程序,解决方案中只有一个项目。 瞄准。net Framework 4.0 使用SharpDevelop 4.3作为我的IDE

听起来很傻,但我碰巧在“资源”上将“逻辑名称”属性设置为“资源”。resx文件”。一旦我清理了那块地,一切都没问题了。

通常,当您将随机文件添加为EmbeddedResource时,您通常希望将逻辑名称设置为合理的名称,出于某种原因,我在资源中也做了同样的操作。Resx文件,这一切都搞砸了…

希望这能帮助到一些人。

This can be caused by mismatched namespaces. The second from top answer (Sibi Elango's) says to right-click the resx file, and change Build option to EmbeddedResource, but I had already done that and still had the error. The top answer (CFinck's) notes a way of fixing this via manually editing files, however, I had this problem in MonoDevelop, and had to set the default namespace to the same as the cs file which was calling for the resource (the file which contained code such as the code below)...

this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));

通过GUI设置默认名称空间后,上面的代码行不再引起异常。

我在尝试在EF上运行update-database命令时遇到了同样的问题。结果发现,抛出异常的迁移将.resx文件排除在项目之外。我只是右键单击。resx文件,然后单击“Include In Project”。 问题解决了。