我有两个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”

其他回答

我也面临着同样的问题,尝试了答案中提到的所有解决方案,但似乎都不起作用。结果在将代码签入TFS期间。TFS没有签入Resx文件,它只签入了设计器文件。因此,所有其他开发人员在他们的机器上运行时都面临着这个问题。手动签入resx文件就可以了

Dotfuscation也会引发此错误,因为resx设计器文件依赖于反射。如果你使用Dotfuscator,它会破坏你的resx文件。您必须始终将它们添加到混淆过程中。

在一个NetCore项目中有类似的问题,我注意到在我添加了我的迁移(让我们将其命名为WhateverMigration)后,作为EmbeddedResource的.resx文件引用没有添加到.csproj中,即使一切看起来都很好。所以我打开我的。csproj文件,添加:

<EmbeddedResource Update="Migrations\202107071914322_WhateverMigration.resx">
    <Generator></Generator>
    <DependentUpon>202107071914322_WhateverMigration.cs</DependentUpon>
</EmbeddedResource>

我是这样解决的:

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

它工作得很完美。

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设置默认名称空间后,上面的代码行不再引起异常。