You may receive a "System.Resources.MissingManifestResourceException" error message when you access the .resources file of the form at run time

Article translations Article translations
Article ID: 318603 - View products that this article applies to.
This article was previously published under Q318603
Expand all | Collapse all

On This Page

SYMPTOMS

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:
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.

WORKAROUND

To work around this problem, change the Resource File Name property of the .resX file of the project. To do this, follow these steps:
  1. Start Visual Studio .NET 2003 or Visual Studio 2005.
  2. Open the project that contains the localized form class where you receive the error message that is mentioned in the "Symptoms" section.
  3. In Solution Explorer, expand all folders.
  4. Right-click Form1.resX, and then click Properties.
  5. In the Form1.resX Property Pages dialog box, expand Configuration Properties, and then click General under Managed Resources.
  6. Change the Resource File Name property from $(IntDir)/ <placeholder> .Form1.resources to $(IntDir)/ <placeholder> . MyForm .resources, and then click OK.

    Note MyForm is a placeholder for the class name of the form class that you localized.
  7. Press CTRL+SHIFT+S to save the project. Press CTRL+SHIFT+B to build the solution. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
    824495 FIX: You receive a "MissingManifestResourceException" error message when you add a linked resource in Visual Studio .NET 2003
  8. Press F5 to run the application. The application runs, and the Form1 form is displayed.
.

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 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

  1. Create a Windows Application project in Visual Basic .NET or in Visual Basic 2005, Visual C# .NET, or Visual J# .NET. Form1 is created by default.Note In Visual Studio 2005, you receive the following warning message:
    Components cannot be added in localization mode. Select (Default) in the Language property to return to the default form and add components.
    Note You must change the code in Visual Basic 2005. By default, Visual Basic creates two files for the project when you create a Windows Forms project. If the form is named Form1, the two files that represent the form are named Form1.vb and Form1.Designer.vb. You write the code in the Form1.vb file. The Windows Forms Designer writes the code in the Form1.Designer.vb file. The Windows Forms Designer uses the partial keyword to divide the implementation of Form1 into two separate files. This behavior prevents the designer-generated code from being interspersed with your code.

    For more information about the new Visual Basic 2005 language enhancements, visit the following Microsoft Developer Network (MSDN) Web site:
    http://msdn2.microsoft.com/en-us/library/ms379584(vs.80).aspx
    For more information about partial classes and the Windows Forms Designer, visit the following MSDN Web site:
    http://msdn2.microsoft.com/en-us/library/ms171843.aspx
  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 mentioned in the "Symptoms" section.

Properties

Article ID: 318603 - Last Review: May 11, 2007 - Revision: 4.3
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 C# .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2003 Standard Edition
Keywords: 
kbvs2005applies kbvs2005swept kbprb KB318603

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com