dotnet / dotnet/winforms

Adding a ToolStripDropDown child to ToolStripPanel throws NRE

Open
#2,973 5 comments 0 reactions 0 assignees View on GitHub
:beetle: bug
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
1d 13m
Merged PRs (30d)
85

Description

```cs
[WinFormsFact]
public void Test()
{
using var control = new ToolStripDropDown
{
TopLevel = false
};
using var parent = new ToolStripPanel();
parent.Controls.Add(control);
}
```

```
Error Message:
System.NullReferenceException : Object reference not set to an instance of an object.
Stack Trace:
at System.Windows.Forms.Layout.FlowLayout.xLayoutRow(ContainerProxy containerProxy, ElementProxy elementProxy, Int32 startIndex, Int32 endIndex, Rectangle rowBounds, Int32& breakIndex, Boolean measureOnly)
at System.Windows.Forms.Layout.FlowLayout.xLayout(IArrangedElement container, Rectangle displayRect, Boolean measureOnly)
at System.Windows.Forms.Layout.FlowLayout.GetPreferredSize(IArrangedElement container, Size proposedConstraints)
at System.Windows.Forms.ToolStripPanelRow.System.Windows.Forms.Layout.IArrangedElement.GetPreferredSize(Size constrainingSize)
at System.Windows.Forms.Layout.FlowLayout.VerticalElementProxy.GetPreferredSize(Size proposedSize)
at System.Windows.Forms.Layout.FlowLayout.xLayoutRow(ContainerProxy containerProxy, ElementProxy elementProxy, Int32 startIndex, Int32 endIndex, Rectangle rowBounds, Int32& breakIndex, Boolean measureOnly)
at System.Windows.Forms.Layout.FlowLayout.xLayout(IArrangedElement container, Rectangle displayRect, Boolean measureOnly)
at System.Windows.Forms.Layout.FlowLayout.LayoutCore(IArrangedElement container, LayoutEventArgs args)
at System.Windows.Forms.Layout.LayoutEngine.Layout(Object container, LayoutEventArgs layoutEventArgs)
at System.Windows.Forms.Control.OnLayout(LayoutEventArgs levent)
at System.Windows.Forms.ToolStripPanel.OnLayout(LayoutEventArgs e)
at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
at System.Windows.Forms.Control.PerformLayout()
at System.Windows.Forms.Control.ResumeLayout(Boolean performLayout)
at System.Windows.Forms.Control.SetBoundsCore(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified specified)
at System.Windows.Forms.ToolStrip.SetBoundsCore(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified specified)
at System.Windows.Forms.ToolStripDropDown.SetBoundsCore(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified specified)
at System.Windows.Forms.Control.SetBounds(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified specified)
at System.Windows.Forms.Control.set_Size(Size value)
at System.Windows.Forms.ToolStripDropDown.AdjustSize()
at System.Windows.Forms.ToolStripDropDown.OnLayout(LayoutEventArgs e)
at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
at System.Windows.Forms.Control.PerformLayout()
at System.Windows.Forms.Control.ResumeLayout(Boolean performLayout)
at System.Windows.Forms.Layout.LayoutTransaction.Dispose()
at System.Windows.Forms.ToolStripPanel.ToolStripPanelControlCollection.AddInternal(Control value)
at System.Windows.Forms.Tests.ControlTests.T() in C:\Users\hughbe\source\repos\ConsoleApp\ControlTests.cs:line 42
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.