Select the product you need help with
- Internet Explorer
- Windows Phone
- More products
You may receive a "System.Resources.MissingManifestResourceException" error message when you access the .resources file of the form at run time
Article ID: 318603 - View products that this article applies to.
This article was previously published under Q318603
When you are running your Visual Basic .NET or Visual Basic 2005, 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:
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:
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
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
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.
To resolve this problem, move all of the other class definitions so that they appear after the form's class definition.
To work around this problem, change the Resource File Name property of the .resX file of the project. To do this, follow these steps:
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 mentioned in the "Symptoms" section.
When you load the form at run time, the InitializeComponent method may have 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
Article ID: 318603 - Last Review: May 11, 2007 - Revision: 4.3