我有一个Windows窗体的应用程序有时会抛出一个"参数无效"在野外例外。在遍历自动生成的代码(由Visual Studio生成)时,在构造时引发异常。
以下是一些相关的代码剪辑。
// MainForm.cs
public partial class MyForm : Form
{
public MyForm(Action shutdown_request_callback = null)
{
Visible = false;
ShowInTaskbar = false;
Opacity = 0;
InitializeComponent();
...
}
}
// MainForm.designer.cs, this is auto-generated
partial class MainForm
{
private void InitializeComponent()
{
...
this.StatusPane = new StatusPaneUserControl();
...
}
}
// StatusPaneUserControl.cs
public partial class StatusPaneUserControl : UserControl
{
public StatusPaneUserControl()
{
InitializeComponent();
}
}
// StatusPaneUserConrol.designer.cs, auto generated code
partial class StatusPaneUserControl
{
private void InitializeComponent()
{
this.FolderImage = new System.Windows.Forms.PictureBox();
...
//
// FolderImage
//
this.FolderImage.Image = ((System.Drawing.Image)(resources.GetObject("FolderImage.Image")));
this.FolderImage.InitialImage = ((System.Drawing.Image)(resources.GetObject("FolderImage.InitialImage")));
this.FolderImage.Location = new System.Drawing.Point(161, 45);
this.FolderImage.Name = "FolderImage";
this.FolderImage.Size = new System.Drawing.Size(251, 219);
this.FolderImage.TabIndex = 8;
this.FolderImage.TabStop = false;
this.FolderImage.WaitOnLoad = true;
...
this.Controls.Add(this.FolderImage);
}
}
"参数无效"异常是从Controls.Add
间接引发的。实际的堆栈如下。
ArgumentException: Parameter is not valid.
at System.Drawing.Image.get_FrameDimensionsList()
at System.Drawing.ImageAnimator.CanAnimate(Image image)
at System.Drawing.ImageAnimator.ImageInfo..ctor(Image image)
at System.Drawing.ImageAnimator.Animate(Image image, EventHandler onFrameChangedHandler)
at System.Windows.Forms.PictureBox.Animate(Boolean animate)
at System.Windows.Forms.Control.AssignParent(Control value)
at System.Windows.Forms.Control.ControlCollection.Add(Control value)
at MyNamespace.StatusPaneUserControl.InitializeComponent()
at MyNamespace.MainForm.InitializeComponent()
at MyNamespace.MainForm..ctor(Action shutdown_request_callback)
异常似乎来自get_FrameDimensionsList()
,它似乎没有采取任何令人困惑的参数,因为异常似乎说某些参数是坏的。
我发现了一个类似的问题here,但与dispose相关,这看起来并不合适(但有意义)。