分享
 
 
 

使用ImageList时候发生运行错误提示资源问题的解决方法

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

今天在给一个程序加入ImageList的时候碰到了这样的运行错误:

未能在给定的程序集中找到任何适合于指定的区域性(或非特定区域性)的资源。请确保已将“frmMain.resources”正确嵌入或链接到程序集“XXX”。

baseName: yyy locationInfo: xxx.yyy resource file name: yyy.resources assembly: XXX, Version=1.0.1698.16471, Culture=neutral, PublicKeyToken=null

其实之前在给这个程序的主窗口自定义icon的时候也碰到过同样的问题,只是当时没有注意。

查找资料,在微软的支持站点发现如下文章:

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q318603

PRB: Error When You Access .resources File of the Form at Run Time

Article ID

:

318603

Last Review

:

August 7, 2003

Revision

:

2.0

This article was previously published under Q318603

On this Page

SYMPTOMS

CAUSE

RESOLUTION

STATUS

MORE INFORMATION

SYMPTOMS

When you are running your Visual Basic .NET, Visual C# .NET, or Visual J# .NET Windows application, you may receive the following error message or a similar one when you load a form:

An unhandled exception of type 'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll

Additional information: Could not find any resources appropriate for the specified culture (or the neutral culture) in the given assembly. Make sure "Form1.resources" was correctly embedded or linked into assembly "myApplication".

baseName: Form1 locationInfo: WindowsApplication4.Form1 resource file name: Form1.resources assembly: myApplication, Version=1.0.781.33026, Culture=neutral, PublicKeyToken=null

If you click

Break in the error dialog box, and if you are running the code in the integrated development environment (IDE), you discover that a line of code inside the InitializeComponent statement causes this problem. For example, if you create the sample from the "More Information" section, this error occurs in conjunction with an ImageList control. Although the error message may refer to a different control, notice that resources.GetObject appears on that line of code in the error message:

this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));

CAUSE

This problem occurs because the Form class is not the first class in the code module of the form.

NOTE: This article documents one specific cause of this problem. There may be other situations that can lead to similar results.

RESOLUTION

To resolve this problem, move all of the other class definitions so that they appear after the form's class definition.

STATUS

This behavior is by design.

MORE INFORMATION

A form code module can contain multiple classes. When the project is built, the build system must decide which class it should use to create the .resources file. The design of the project build system specifies that the first class in the code module is the class on which the .resources file is based. The .resources file is named according to that class, not the name of the form. In most cases, these two names are the same. However, if these names differ, you receive the error message that is listed in the "Symptoms" section.

When you load the form at run time, the InitializeComponent method may need to get objects from the .resources file. InitializeComponent searches for the Form_Name.resources file in the assembly. Because the initial Form_Name.resources file was never created or linked to the assembly, the attempt to retrieve the .resources file fails.

Steps to Reproduce the Behavior

1.

Create a Windows Application project in Visual Basic .NET, Visual C# .NET, or Visual J# .NET. Form1 is created by default.

2.

Add an ImageList control to Form1.

3.

Add an icon file to the ImageList control.

4.

In the code module of Form1, add the following code before the Form1 definition: Visual Basic .NET: Public Class someClass

End Class

Visual C# .NET and Visual J# .NET: public class someClass

{

}

5.

Build the project. Notice that the project builds successfully.

6.

Run the project. Notice that you receive the error message that is listed in the "Symptoms" section.

APPLIES TO

Microsoft Visual Basic .NET 2002 Standard Edition

Microsoft Visual C# .NET 2002 Standard Edition

Microsoft Visual J# .NET 2003 Standard Edition

Microsoft Visual J# .NET 2003 Standard Edition

Microsoft Visual C# .NET 2003 Standard Edition

Microsoft Visual Basic .NET 2003 Standard Edition

把主窗体的类提到程序最前面,问题解决。^_^

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有