如何修复 Visual Studio 的 C++ CLR 空项目(.NET Framwork)中的“System.Resources.MissingManifestResourceException:”?

问题描述 投票:0回答:1

所以我对 GUI 非常陌生,并尝试使用 Visual Studio(.Net 框架)学习和构建一个简单的 GUI。是登录成功后打开另一个表单的登录。我使用计算机上的图像作为登录表单的背景,并尝试将其用于其他表单。尝试运行 UI 时出现“System.Resources.MissingManifestResourceException:”异常。

它也出现在我使用图片框以相同形式放置计算机中的图像的代码中。

这是背景代码:

this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"$this.BackgroundImage")));   // exception appears here //
this->ClientSize = System::Drawing::Size(660, 390);
this->Controls->Add(this->button7);
this->Controls->Add(this->button6);
this->Controls->Add(this->button5);
this->Controls->Add(this->button4);
this->Controls->Add(this->button3);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->label1);

图像框代码:

this->pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"pictureBox1.Image"))); //appears here //
this->pictureBox1->Location = System::Drawing::Point(73, 130);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(162, 141);
this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
this->pictureBox1->TabIndex = 22;
this->pictureBox1->TabStop = false;

我尝试删除图像并运行,但我尝试将它们添加回来,但它产生了同样的问题。 通过使用表单的头文件.h,我删除了从属性侧面板中选择的“BackgroundImage”图像。

UI Windows 窗体通过 Visual Studio 项目栏下的“By ADD New Item”来开发 GUI。

有什么原因吗?

c++ winforms user-interface visual-studio-2022 .net-4.8
1个回答
0
投票

最常见的原因是您在创建资源文件后更改了命名空间名称。

例如。

Project1 -> Project12

System.Resources.MissingManifestResourceException:'找不到任何 适合特定文化或中立的资源 文化。确保“Project12.MyForm.resources”正确 在编译时嵌入或链接到程序集“Project1”中,或者 所有所需的卫星程序集均可加载并已完全签名。'

解决方案: 打开vcxproj文件 -> 找到resx文件位置:添加标签NewNamespace.YourClass.resources。

喜欢:

<LogicalName>Project12.MyForm.resources</LogicalName>

 <EmbeddedResource Include="MyForm.resx">
<LogicalName>Project12.MyForm.resources</LogicalName>
      <DependentUpon>MyForm.h</DependentUpon>
      <SubType>Designer</SubType>
    </EmbeddedResource>
© www.soinside.com 2019 - 2024. All rights reserved.