Microsoft KB Archive/895579

From BetaArchive Wiki

Article ID: 895579

Article Last Modified on 12/3/2007



APPLIES TO

  • Microsoft .NET Framework 1.1 Service Pack 1




SYMPTOMS

In the Microsoft .NET Framework 1.1 Service Pack 1 (SP1), when you merge parent menus and child menus, a run-time error may occur, and you may receive an exception that is similar to the following:

System.NullReferenceException: Object reference not set to an instance of an object.

Note You may merge parent menus and child menus in a Multiple Document Interface (MDI) form-based application.

RESOLUTION

A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next .NET Framework 1.1 service pack that contains this hotfix.

To resolve this problem immediately, contact Microsoft Product Support Services to obtain the hotfix. For a complete list of Microsoft Product Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:

Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.

Prerequisites

The .NET Framework 1.1

Restart requirement

You do not have to restart the computer after you apply this hotfix.

Hotfix replacement information

This hotfix does not replace any other hotfixes.

The English version of this hangout has the file attributes (or later file attributes) that are listed in the following table. The dates and times for these files are listed in Coordinated Universal Time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.

   Date         Time   Version        Size       File name
   ----------------------------------------------------------------------
   09-Mar-2005  20:14  1.1.4322.2303  2,056,192  System.windows.forms.dll  

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

Steps to reproduce the problem

  1. Start Microsoft Visual Studio .NET 2003.
  2. On the File menu, click New, and then click Project.
  3. Click Visual C# Projects, click Windows Application, and then click OK.
  4. In Solution Explorer, right-click Form1.cs, click View Code, and then replace all the code that is in Form1.cs with the following code.

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    
    namespace MDIMenuTest
    {
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.MainMenu mainMenu1;
    private System.Windows.Forms.MenuItem menuMain;
    private System.Windows.Forms.MenuItem MenuFromMain;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;
    
    public Form1()
    {
    //
    // Required for Windows Form Designer support.
    //
    InitializeComponent();
    
    // create a new child.
    Child formChild = new Child();
    formChild.MdiParent = this; // set parent
    formChild.Show(); // display child
    }
    
    /// <summary>
    /// Clean up any resources that are used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    }
    
    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support. Do not modify
    /// the contents of this method by using the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.mainMenu1 = new System.Windows.Forms.MainMenu();
    this.menuMain = new System.Windows.Forms.MenuItem();
    this.MenuFromMain = new System.Windows.Forms.MenuItem();
    // 
    // mainMenu1
    // 
    this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
    this.menuMain});
    // 
    // menuMain
    // 
    this.menuMain.Index = 0;
    this.menuMain.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
    this.MenuFromMain});
    this.menuMain.MergeType = System.Windows.Forms.MenuMerge.MergeItems;
    this.menuMain.Text = "Menu"
    // 
    // MenuFromMain
    // 
    this.MenuFromMain.Index = 0;
    this.MenuFromMain.Text = "MenuFromMain"
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(292, 266);
    this.IsMdiContainer = true;
    this.Menu = this.mainMenu1;
    this.Name = "Form1"
    this.Text = "Form1"
    this.Load += new System.EventHandler(this.Form1_Load);
    
    }
    #endregion
    
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    }
    
    
    }
    }
  5. On the Project menu, click Add Windows Form, click Windows Form under Templates, name the form Child.cs, and then click Open.
  6. In Solution Explorer, right-click Child.cs, click View Code, and then replace all the code that is in Child.cs with the following code.

    using System;
    
    using System.Drawing;
    
    using System.Collections;
    
    using System.ComponentModel;
    
    using System.Windows.Forms;
    
    using System.Diagnostics;
    
    
    
    namespace MDIMenuTest
    
    {
    
    /// <summary>
    
    /// Summary description for Child.
    
    /// </summary>
    
    public class Child : System.Windows.Forms.Form
    
    {
    
    private System.Windows.Forms.MainMenu mainMenu1;
    
    private System.Windows.Forms.MenuItem menuMain;
    
    private System.Windows.Forms.MenuItem MenuFromChild;
    
    private System.Windows.Forms.MenuItem menuItem1;
    
    /// <summary>
    
    /// Required designer variable.
    
    /// </summary>
    
    private System.ComponentModel.Container components = null;
    
    
    
    public Child()
    
    {
    
    //
    
    // Required for Windows Form Designer support.
    
    //
    
    InitializeComponent();
    
    
    
    //
    
    // TODO: Add any constructor code after the InitializeComponent call.
    
    //
    
    }
    
    
    
    /// <summary>
    
    /// Clean up any resources that are used.
    
    /// </summary>
    
    protected override void Dispose( bool disposing )
    
    {
    
    if( disposing )
    
    {
    
    if(components != null)
    
    {
    
    components.Dispose();
    
    }
    
    }
    
    base.Dispose( disposing );
    
    }
    
    
    
    #region Windows Form Designer generated code
    
    /// <summary>
    
    /// Required method for Designer support. Do not modify
    
    /// the contents of this method by using the code editor.
    
    /// </summary>
    
    private void InitializeComponent()
    
    {
    
    this.mainMenu1 = new System.Windows.Forms.MainMenu();
    
    this.menuMain = new System.Windows.Forms.MenuItem();
    
    this.MenuFromChild = new System.Windows.Forms.MenuItem();
    
    // 
    
    // mainMenu1
    
    // 
    
    this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
    
    this.menuMain});
    
    // 
    
    // menuMain
    
    // 
    
    this.menuMain.Index = 0;
    
    this.menuMain.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
    
    this.MenuFromChild,
    
    });
    
    this.menuMain.MergeType = System.Windows.Forms.MenuMerge.MergeItems;
    
    this.menuMain.Text = "Menu"
    
    this.menuMain.Popup += new System.EventHandler(this.menuMain_Popup);
    
    // 
    
    // MenuFromChild
    
    // 
    
    this.MenuFromChild.Index = 0;
    
    this.MenuFromChild.Text = "MenuFromChild"
    
    
    
    // 
    
    // Child
    
    // 
    
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    
    this.ClientSize = new System.Drawing.Size(292, 266);
    
    this.Menu = this.mainMenu1;
    
    this.Name = "Child"
    
    this.Text = "Child"
    
    
    
    }
    
    #endregion
    
    
    
    private void menuMain_Popup(object sender, System.EventArgs e)
    
    {
    
    // The goal is to dynamically change the child menu items during run time.
    
    // Then, the new child menu items will be merged into the MDI main menu automatically by the .NET Framework.
    
    // However, the program crashed after it tried to add the following menu item to the MDI menu.
    
    MenuItem menuItem = new MenuItem("New Menu Item From Child");
    
    this.menuMain.MenuItems.Add(menuItem);
    
    }
    
    }
    
    }
  7. On the Debug menu, click Start to compile and then run the project.
  8. In the new application, click any menu choice. You receive the following error message:

    Object reference not set to an instance of an object

For the original release version of the .NET Framework 1.1

This article outlines the same problem that is documented in Microsoft Knowledge Base Article 890328. However, the hotfix that is associated with this article is for the .NET Framework 1.1 SP1. Hotfix 890328 is only for the original release version of the .NET Framework 1.1.

For more information, click the following article number to view the article in the Microsoft Knowledge Base:

824684 Description of the standard terminology that is used to describe Microsoft software updates


Keywords: kbwinserv2003sp2fix kbhotfixserver kbqfe kbprb kbfix kbbug KB895579