Franklin_Skipdiddle
Franklin_Skipdiddle

Reputation: 225

Program crashes on calling InitializeComponent()

OK. This one is a bit of a doozy.

I'm coding a front-end for an Access database (I know, reinventing the wheel). This front-end is simple. Either an individual can add a new entry, or search existing entries. Both of those are working fine. The program is self-updating, though is very simple. It compares the current file version (not assembly) of the executed program, and references itself with a remote drives version to see which is newer. If the remote drive's executable is newer, I generate a batch file to update the script via killing the current program, copying the newer program to the same directory as the old, and automatically opening the new program. This update check occurs every time the user opens the program.

I'm not sure if that's relevant, but I have recently been editing that process to work on both XP and 7. Therefore, I needed to modify it to accommodate spaces in the file path (Documents and Settings - XP). That's all fine and dandy.

Out of nowhere (it seems), the program started consistently crashing on my test XP machine (verified on 2 different XP machines). My personal machine is running 7, and operates exactly as desired, including the update, just fine.

The crash on XP is an unhandled exception right at the InitializeComponent() of my Home form. The quick layout of my forms is as follows:

We won't get into the other forms, because it crashes before loading Home.cs form.

I've narrowed it down to crashing within InitializeComponent() of Home, within the following constructor:

public Home(string DB)
    {
        InitializeComponent();
        database = DB;
        lblVersion.Text = "Version: " + FileVersionInfo.GetVersionInfo(Directory.GetCurrentDirectory() + "\\KnowledgeBase.exe").ProductVersion;
    }

and with the following message. Sorry for graininess...screenshot of a screenshot: I've less than 10 rep, and will not type out the error:

enter image description here

Here's my InitializeComponent()

private void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Home));
        this.btnNewEntry = new System.Windows.Forms.Button();
        this.label1 = new System.Windows.Forms.Label();
        this.label2 = new System.Windows.Forms.Label();
        this.btnSearch = new System.Windows.Forms.Button();
        this.lblVersion = new System.Windows.Forms.Label();
        this.linklblChangelog = new System.Windows.Forms.LinkLabel();
        this.button1 = new System.Windows.Forms.Button();
        this.pictureBox1 = new System.Windows.Forms.PictureBox();
        ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
        this.SuspendLayout();
        // 
        // btnNewEntry
        // 
        this.btnNewEntry.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.btnNewEntry.Location = new System.Drawing.Point(391, 407);
        this.btnNewEntry.Name = "btnNewEntry";
        this.btnNewEntry.Size = new System.Drawing.Size(142, 43);
        this.btnNewEntry.TabIndex = 0;
        this.btnNewEntry.Text = "Add new entry";
        this.btnNewEntry.UseVisualStyleBackColor = true;
        this.btnNewEntry.Click += new System.EventHandler(this.btnNewEntry_Click);
        // 
        // label1
        // 
        this.label1.AutoSize = true;
        this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 20F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.label1.Location = new System.Drawing.Point(184, 9);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(349, 31);
        this.label1.TabIndex = 1;
        this.label1.Text = "Nationwide Knowledgebase";
        // 
        // label2
        // 
        this.label2.AutoSize = true;
        this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.label2.Location = new System.Drawing.Point(280, 41);
        this.label2.Name = "label2";
        this.label2.Size = new System.Drawing.Size(147, 26);
        this.label2.TabIndex = 2;
        this.label2.Text = "RADS Edition";
        // 
        // btnSearch
        // 
        this.btnSearch.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.btnSearch.Location = new System.Drawing.Point(190, 407);
        this.btnSearch.Name = "btnSearch";
        this.btnSearch.Size = new System.Drawing.Size(142, 43);
        this.btnSearch.TabIndex = 3;
        this.btnSearch.Text = "Search database";
        this.btnSearch.UseVisualStyleBackColor = true;
        this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
        // 
        // lblVersion
        // 
        this.lblVersion.AutoSize = true;
        this.lblVersion.Location = new System.Drawing.Point(3, 485);
        this.lblVersion.Name = "lblVersion";
        this.lblVersion.Size = new System.Drawing.Size(64, 13);
        this.lblVersion.TabIndex = 4;
        this.lblVersion.Text = "Version: null";
        // 
        // linklblChangelog
        // 
        this.linklblChangelog.AutoSize = true;
        this.linklblChangelog.Location = new System.Drawing.Point(96, 485);
        this.linklblChangelog.Name = "linklblChangelog";
        this.linklblChangelog.Size = new System.Drawing.Size(58, 13);
        this.linklblChangelog.TabIndex = 5;
        this.linklblChangelog.TabStop = true;
        this.linklblChangelog.Text = "Changelog";
        // 
        // button1
        // 
        this.button1.Location = new System.Drawing.Point(640, 480);
        this.button1.Name = "button1";
        this.button1.Size = new System.Drawing.Size(75, 23);
        this.button1.TabIndex = 7;
        this.button1.Text = "test";
        this.button1.UseVisualStyleBackColor = true;
        this.button1.Visible = false;
        this.button1.Click += new System.EventHandler(this.button1_Click);
        // 
        // pictureBox1
        // 
        this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
        this.pictureBox1.Location = new System.Drawing.Point(232, 85);
        this.pictureBox1.Name = "pictureBox1";
        this.pictureBox1.Size = new System.Drawing.Size(247, 256);
        this.pictureBox1.TabIndex = 8;
        this.pictureBox1.TabStop = false;
        // 
        // Home
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.BackColor = System.Drawing.SystemColors.GradientInactiveCaption;
        this.ClientSize = new System.Drawing.Size(727, 512);
        this.Controls.Add(this.pictureBox1);
        this.Controls.Add(this.button1);
        this.Controls.Add(this.linklblChangelog);
        this.Controls.Add(this.lblVersion);
        this.Controls.Add(this.btnSearch);
        this.Controls.Add(this.label2);
        this.Controls.Add(this.label1);
        this.Controls.Add(this.btnNewEntry);
        this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
        this.Name = "Home";
        this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
        this.Text = "Home";
        this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Home_FormClosed);
        ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
        this.ResumeLayout(false);
        this.PerformLayout();

    }

Why is it crashing on InitializeComponent() ONLY on XP? And why has it JUST started doing it? The first couple weeks of development went smoothly in this area.

I've tried taking out the entire Update() process, but that doesn't change anything.

Thanks for reading.

UPDATE: Jon Skeet has suggested it the icon I was using crashed the program. Turns out it did. Removing the icon lets the form work properly on XP (again, never was a problem on 7). More interestingly, the problem waited 2 weeks to show its face, as I've been using this icon in development for that long. I'll attack the reason why it happened later, but I've got more code to write in the meantime.

Thanks everyone.

Upvotes: 2

Views: 2406

Answers (2)

user153923
user153923

Reputation:

Put yourself a breakpoint inside your InitializeComponent() method, and step through it.

Like Jon has already said, it is likely a problem with your icon:

    this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));

The debugger should be able to step through, line-by-line, until you hit the offending section of code.

Upvotes: 1

Jon Skeet
Jon Skeet

Reputation: 1503379

Given the stack trace, I suspect this is the problem:

this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));

I'd confirm that by removing the icon to start with and see whether that fixes the issue. Assuming it does, look at what format the icon's in - I wonder whether either it's somehow become corrupted in a way which XP can't handle, or it's using some later image format than XP supports.

Of course if the icon isn't important, you could just leave it out entirely :) Still, I'd try to diagnose what's happened to it...

Upvotes: 5

Related Questions