我有两个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项目。


当前回答

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

其他回答

我是这样解决的:

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

它工作得很完美。

在我的情况下,资源文件的构建动作已经是嵌入式资源,但每次我运行update-database,我得到了相同的错误,所以我做了其他步骤,它是有效的:

将“生成操作”属性更改为“编译” 构建(有很多错误) 将“生成操作”属性更改回“嵌入式资源” - database就

出于某种原因,它起作用了。

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

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

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

另一件要检查的事情是你是否在EmbeddedResource上定义了LogicalName或ManifestResourceName。如果您的项目文件正在使用它们,请确保它们被适当地定义,因为它们可能导致资源使用您不期望的名称。