Microsoft KB Archive/890328

From BetaArchive Wiki

Article ID: 890328

Article Last Modified on 12/27/2006



APPLIES TO

  • Microsoft .NET Framework 1.1



Notice

For users who have the Microsoft .NET Framework 1.1 Service Pack 1 installed

This article discusses the same problem that is discussed in Microsoft Knowledge Base (KB) article 895579. However, the hotfix that this article discusses is only for the original release version of the .NET Framework 1.1. If you have the .NET Framework 1.1 Service Pack 1 (SP1) installed, use the hotfix that is discussed in KB article 895579. For more information, click the following article number to view the article in the Microsoft Knowledge Base:

895579 FIX: You receive a "System.NullReferenceException" exception when you merge parent menus and child menus in an MDI form-based application in the .NET Framework 1.1 Service Pack 1


SYMPTOMS

In the Microsoft .NET Framework 1.1, when you merge parent and child menus, a runtime error may occur and you may receive an exception error message that resembles the following:

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

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

RESOLUTION

Hotfix information

A supported hotfix is now available from Microsoft. However, it is intended to correct only the problem that is described in this article. Apply it only 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 Customer Support Services to obtain the hotfix. For a complete list of Microsoft Customer 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.

File information

The English version of this hotfix 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 item in Control Panel.

  Date         Time   Version        Size       File name
  ----------------------------------------------------------------------
  01-Dec-2004  04:08  1.1.4322.1090  1,703,936  System.Design.dll
  01-Dec-2004  04:04  1.1.4322.1090    466,944  System.Drawing.dll
  01-Dec-2004  04:13  1.1.4322.1090  2,048,000  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 new child
                Child formChild = new Child();
                formChild.MdiParent = this;   // set parent
                formChild.Show();          // display child
            }
    
            /// <summary>
            /// Clean up any resources being 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 with 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 InitializeComponent call
    
                //
    
            }
    
     
    
            /// <summary>
    
            /// Clean up any resources being 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 with 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 trying 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 more information about software update terminology, 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: kbqfe kbfix kbbug kbhotfixserver KB890328