c# – 关于resources.ApplyResources的System.Resources.MissingManifestResourceException

这是我正在努力的代码:

System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(EditorPane));
this.editorControl = new EditorControl();
resources.ApplyResources(this.editorControl, "editorControl", CultureInfo.CurrentUICulture);

当代码执行时,它抛出一个’System.Resources.MissingManifestResourceException’,所有错误消息都只是吼叫.

An exception of type ‘System.Resources.MissingManifestResourceException’ occurred in mscorlib.dll but was not handled in user code

Additional information: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure “Editor.EditorPane.resources” was correctly embedded or linked into assembly “Editor” at compile time, or that all the satellite assemblies required are loadable and fully signed.

最佳答案 对我来说,问题不是任何内部类定义.相反,问题源是在项目文件中,这花了我很长时间才发现.

这是我在项目文件中找到的:

<EmbeddedResource Include="Main.resx" />

这就是它必须:

<EmbeddedResource Include="Main.resx">
  <DependentUpon>Main.pas</DependentUpon>
</EmbeddedResource>

如果没有列出这种依赖关系(我必须强调,我没有自己删除它 – 它是在某个阶段由MS Visual Studio完成的),必要的资源文件没有在编译例程中正确包含.

我希望这会有所帮助(并让其他人头疼)!

点赞