-1

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.

leppie
  • 115,091
  • 17
  • 196
  • 297
Robert Koernke
  • 436
  • 3
  • 18
  • I don't see any subscription to the event like `this.Load += new System.EventHandler(this.Form_Load);` Are you subscribed? – Ondrej Janacek Jan 08 '15 at 16:43
  • 1
    Can you post the code where you show this form. Youre code seems fine – Sievajet Jan 08 '15 at 16:56
  • 2
    There is no scenario where it doesn't run OnLoad() if you make the form visible. Look in the Output window, you probably see a "First chance exception" notification. [Read this](http://stackoverflow.com/a/4934010/17034). – Hans Passant Jan 08 '15 at 17:07
  • Hey Ondrej: I wondered that myself; As I picked this app from a previous developer. But oddly adding this.Load += new System.EventHandler(this.Form_Load); Neither event is triggering. Does that mean something else is wrong? – Robert Koernke Jan 08 '15 at 17:17
  • I'm not getting a 1st chance exception – Robert Koernke Jan 08 '15 at 17:32
  • RE: Sievajet This is the 1st form to run. as in - Application.Run(instance) where instance = MdiParent1 The form does appear, or becomes visible as Hans points out, but no events?! – Robert Koernke Jan 08 '15 at 17:41
  • Oh d'oh I had 'Just-My-Code' enabled, and when I turned that off, I found this: A first chance exception of type 'System.IO.FileLoadException' occurred in System.Windows.Forms.dll. This is such a big project that loads lots of 3rd party stuff. – Robert Koernke Jan 08 '15 at 19:56
  • So here is the real problem, something is still referenced backwards: A first chance exception of type 'System.IO.FileLoadException' occurred in System.Windows.Forms.dll Additional information: Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information. – Robert Koernke Jan 08 '15 at 20:08

1 Answers1

0

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.

Robert Koernke
  • 436
  • 3
  • 18