行。这个有点荒谬。
我正在编写Access数据库的前端(我知道,重新发明轮子)。这个前端很简单。个人可以添加新条目,也可以搜索现有条目。这两个都很好。该程序是自我更新的,但非常简单。它比较执行程序的当前文件版本(而不是程序集),并将自身引用到远程驱动器版本以查看哪个更新。如果远程驱动器的可执行文件较新,我生成批处理文件以通过终止当前程序来更新脚本,将较新的程序复制到与旧程序相同的目录,并自动打开新程序。每次用户打开程序时都会进行此更新检查。
我不确定这是否相关,但我最近一直在编辑该过程以在XP和7上工作。因此,我需要修改它以适应文件路径中的空格(Documents and Settings - XP)。这一切都很好,花花公子。
无处不在(似乎),程序开始在我的测试XP机器上崩溃(在2台不同的XP机器上验证)。我的个人计算机正在运行7,并且完全按照需要运行,包括更新,就好了。
在我的Home表单的InitializeComponent()上,XP崩溃是一个未处理的异常。我的表单的快速布局如下:
我们不会进入其他形式,因为它在加载Home.cs表单之前崩溃。
我已将其缩小到Home的InitializeComponent()中,在以下构造函数中崩溃:
public Home(string DB)
{
InitializeComponent();
database = DB;
lblVersion.Text = "Version: " + FileVersionInfo.GetVersionInfo(Directory.GetCurrentDirectory() + "\\KnowledgeBase.exe").ProductVersion;
}
并带有以下消息。对不起谷物...截图截图: 我不到10个代表,并且不会输入错误:
这是我的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();
}
为什么它只在XP上的InitializeComponent()崩溃?为什么它刚刚开始这样做?这个领域的前几周发展进展顺利。
我已经尝试取出整个Update()过程,但这并没有改变任何内容。
感谢阅读。
更新: Jon Skeet建议我使用的图标崩溃程序。事实证明它确实如此。删除图标可以使表单在XP上正常工作(再次,7上从未出现问题)。更有趣的是,这个问题等了2个星期才显露出来,因为我在开发过程中一直使用这个图标。我会攻击它之后发生的原因,但在此期间我还有更多的代码要写。
谢谢大家。
答案 0 :(得分:4)
鉴于堆栈跟踪,我怀疑这是问题所在:
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
我确认通过删除图标开始并查看是否可以解决问题。假设确实如此,请查看图标的格式 - 我想知道它是否以某种方式在XP无法处理的情况下被破坏,或者它使用的是比XP支持的更晚的图像格式。
当然,如果图标不重要,你可以完全放弃它:)但是,我会尝试诊断它发生了什么......
答案 1 :(得分:1)
在InitializeComponent()
方法中加入一个断点,并逐步完成。
就像Jon已经说过的那样,你的图标可能有问题:
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
调试器应该能够逐行执行,直到遇到有问题的代码段。