'"Parameter is not valid" Exception from get_FrameDimensionsList() on form construction
I have an application with a Windows Form which sometimes throws a "Parameter is not valid" exception in the wild. The exception is raised at construction time while traversing auto-generated code (generated by Visual Studio).
Here are some relevant code snips.
// 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);
}
}
The "Parameter is not valid" exception is raised indirectly from Controls.Add. The actual stack is below.
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)
The exception seems to come from get_FrameDimensionsList() which doesn't seem to take any parameters which is confusing since the exception seems to say that some param is bad.
I found a similar question here but is related to dispose which doesn't look applicable here (but would make sense).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
