You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MenuStrip引发MissingManifestResourceException错误的解决方法

迁移VS2008/.NET2.0项目到VS2022/.NET4.8时的MissingManifestResourceException问题解决

问题背景

将基于Visual Studio 2008、.NET 2.0的旧游戏编辑器项目迁移至Visual Studio 2022、.NET 4.8后,启动编辑器时抛出异常:

System.Resources.MissingManifestResourceException: '找不到适合指定区域性或中性区域性的任何资源。请确保在编译时“editor.window_ide.resources”已正确嵌入或链接到程序集“editor”中,或者确保所有必需的附属程序集都可加载并已完全签名。'

异常触发代码行:
resources->ApplyResources(this->menuStrip, L"menuStrip"); this->menuStrip->Name = L"menuStrip";

项目默认命名空间为editor,相关代码结构如下:

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

namespace editor {

    public ref class window_ide : public System::Windows::Forms::Form
    {
        typedef Form    super;
    public:
        window_ide( editor_world& world ) :
            m_editor_world          ( world )
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
            in_constructor  ( );
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~window_ide()
        {
            if (components)
            {
                delete components;
            }

            custom_finalize ( );
        }

private:
    /// <summary>
    /// Required designer variable.
    /// </summary>
    System::ComponentModel::Container^ components;

private: System::Windows::Forms::MenuStrip^  menuStrip;

#pragma region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        {
                  System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(window_ide::typeid));

               // other declared components

          this->menuStrip = (gcnew System::Windows::Forms::MenuStrip());

          this->menuStrip->SuspendLayout();

          this->SuspendLayout();

            // menuStrip
this->menuStrip->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(5) {this->FileMenuItem, this->EditMenuItem, this->ViewMenuItem, this->ToolsMenuItem, this->HelpMenuItem});
            this->menuStrip->SuspendLayout();
            resources->ApplyResources(this->menuStrip, L"menuStrip");
            this->menuStrip->Name = L"menuStrip";
        }
#pragma endregion
};
} // namespace editor

已尝试修改resx文件,将menuStrip.Name值改为System.Windows.Forms.MenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089,或在resx中创建MenuStrip字符串并添加该内容,但均无效。

解决方案

1. 检查资源文件的命名与嵌入属性

  • 确保对应的resx文件命名为window_ide.resx,且目录结构匹配editor命名空间(若项目根目录对应命名空间,可直接放在根目录)。
  • 选中resx文件,设置属性:
    • 生成操作:嵌入的资源
    • 自定义工具:ResXFileCodeGenerator
    • 自定义工具命名空间:editor(必须与类的命名空间完全一致)

2. 修正ComponentResourceManager初始化逻辑

旧版.NET资源查找逻辑与新版存在差异,可显式指定资源程序集:

// 替换原资源管理器初始化代码
Assembly^ currentAssembly = Assembly::GetExecutingAssembly();
System::ComponentModel::ComponentResourceManager^ resources = 
    gcnew System::ComponentModel::ComponentResourceManager(
        currentAssembly, 
        "editor.window_ide" // 资源完整名称:命名空间+类名
    );

3. 清理并重建项目

  • 删除项目的bin和obj目录,清除编译残留文件
  • 在VS2022中依次执行清理解决方案、重建解决方案,确保资源文件被正确嵌入

4. 检查resx文件内部结构

打开resx文件,确认:

  • 控件资源项的Name字段格式为window_ide.menuStrip(类名+控件名)
  • 删除之前手动修改的错误资源项,让设计器重新生成正确的资源配置

5. 验证资源嵌入情况

使用ILDasm工具打开编译后的程序集(editor.dll或editor.exe):

  • 展开Manifest节点,查找.mresource条目,确认存在editor.window_ide.resources资源项

内容的提问来源于stack exchange,提问作者taburetka

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 15:00:37