Search code examples
c#.netwinformsmdiparent

override Onload not firing 4.5 framework


I am working with a Winforms project, on a MDI control. I just spent a bit of time moving the framework from 2.0 to 4.5. I knew I would have some issues, but this one I didn't see coming.

I'm not getting a simple override 'OnLoad' event that is used quite often to fire. Yet they fire in the 2.0 version. I googled for a while, and can't see any reason why not.

Here is some code to look at:

public partial class MDIParent1 : Form
{

    public void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager(typeof(MDIParent1));
        // 
        // MDIParent1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.BackColor = System.Drawing.Color.WhiteSmoke;
        this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
        this.ClientSize = new System.Drawing.Size(1133, 223);
        this.Controls.Add(this.IconStrip_1);
        this.Controls.Add(this.pnlThumbnails);
        this.Controls.Add(this.statusStrip);
        this.Cursor = System.Windows.Forms.Cursors.Default;
        this.ForeColor = System.Drawing.SystemColors.WindowText;
        this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
        this.IsMdiContainer = true;
        this.KeyPreview = true;
        this.Location = new System.Drawing.Point(20, 20);
        this.Menu = this.mainMenu1;
        this.Name = "MDIParent1";
        this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
        this.Text = "Youll never know what this actually said";
        this.TransparencyKey = System.Drawing.Color.Yellow;
        this.statusStrip.ResumeLayout(false);
        this.statusStrip.PerformLayout();
        this.pnlThumbnails.ResumeLayout(false);
        this.thumbsTableLayoutPanel.ResumeLayout(false);
        this.tabThumbnails.ResumeLayout(false);
        this.IconStrip_1.ResumeLayout(false);
        this.IconStrip_1.PerformLayout();
        this.ResumeLayout(false);
        this.PerformLayout();
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        ...
        //Not Firing! in 4.5?!
    }   
}

I cut up what I thought might help you figure out my issue. Keep in mind it worked in 2.0, but not when I cranked it up to 4.5. It does build, but oddly, not fire this event. Of course this is a major piece of software, and there are events like it all-over the project.


Solution

  • I needed to disable 'Just my code', then listen to 'Hans Passant' who commented above and look for a 'First chance Exception' Which took the form of a FileLoadException. But the real problem was there was still references to some 2.0 code being run in the background before the form actually loaded. I solved this in the temp, by putting this in the AppConfig: <startup useLegacyV2RuntimeActivationPolicy="true"> Then my OnLoad began to fire.