[8.0.100-preview.5.23264.1] System.IndexOutOfRangeException thrown when ToolStrips Location is not using default Location in ToolStripContainer
See original GitHub issue.NET version
8.0.100-preview.5.23264.1
Did it work in .NET Framework?
Yes
Did it work in any of the earlier releases of .NET Core or .NET 5+?
Yes
Verify Scenarios:
- Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.5.23264.1: Fail
- Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.4.23259.1: Pass
- Windows10 21h2 x64 + dotnet-sdk-6.0.409: Pass
Issue description
In dotnet-sdk-8.0.100-preview.5.23264.1, when drag the ToolStrip control to change its default location, it will throw System.IndexOutOfRangeException.
Application Name: mRemoteNG OS: Windows 10 21H2 CPU: X64 .NET Build Number: dotnet-sdk-8.0.100-preview.5.23264.1 Github link: https://github.com/mRemoteNG/mRemoteNG App or App Source checking at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1819231
Steps to reproduce
Repro Steps:
- Launch mRemoteNG.exe
Expected Result: App launches successful.
Actual Result: App launches failed with following error in Windows EvntView log:
Description: The process was terminated due to an unhandled exception.
Exception Info: System.TypeInitializationException: The type initializer for 'mRemoteNG.UI.Forms.FrmMain' threw an exception.
---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Windows.Forms.ToolStripPanelRow.ToolStripPanelRowControlCollection.GetControl(Int32 index)
at System.Windows.Forms.ToolStripPanelRow.HorizontalRowManager.JoinRow(ToolStrip toolStripToDrag, Point locationToDrag)
at System.Windows.Forms.ToolStripPanel.MoveInsideContainer(ToolStrip toolStripToDrag, Point clientLocation)
at System.Windows.Forms.ToolStripPanel.Join(ToolStrip toolStripToDrag, Point location)
at System.Windows.Forms.ToolStripPanel.JoinControls(Boolean forceLayout)
at System.Windows.Forms.ToolStripPanel.EndInit()
at System.Windows.Forms.Control.ResumeLayout(Boolean performLayout)
at mRemoteNG.UI.Forms.FrmMain.InitializeComponent() in C:\upgrade\mRemoteNG\mRemoteNG\UI\Forms\frmMain.Designer.cs:line 229
at mRemoteNG.UI.Forms.FrmMain..ctor() in C:\upgrade\mRemoteNG\mRemoteNG\UI\Forms\frmMain.cs:line 67
at mRemoteNG.UI.Forms.FrmMain..cctor() in C:\upgrade\mRemoteNG\mRemoteNG\UI\Forms\frmMain.cs:line 43
--- End of inner exception stack trace ---
at mRemoteNG.UI.Forms.FrmMain.get_Default() in C:\upgrade\mRemoteNG\mRemoteNG\UI\Forms\frmMain.cs:line 43
at mRemoteNG.App.ProgramRoot.CurrentDomainOnUnhandledException(Object sender, UnhandledExceptionEventArgs e) in C:\upgrade\mRemoteNG\mRemoteNG\App\ProgramRoot.cs:line 119
Minimal Repro steps: Demo attached:TopToolStripPanelDemo.zip
1.Create a default WinForm project. 2. Drag a ToolStripContainer control to Form1 3. Drag two ToolStrip controls (toolStrip1 and toolStrip2) into top panel of ToolStripContainer. 4. Drag the toolStrip2 behind to the toolStrip1 (by default, the toolStrip2 is under toolStrip1). 5. Build the project. 6. Change the runtime.config file to let the app run against with dotnet sdk 8.0.100-preview.5.23264.1:
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "8.0.0-preview.5.23260.3"
},
{
"name": "Microsoft.WindowsDesktop.App",
"version": "8.0.0-preview.5.23261.7"
}
]
- Launch the demo app.
Expected Result: App will launch successful.
Actual Result: Launch failed with exception “Index was outside the bounds of the array.”.
Stacktrace:
at System.Windows.Forms.ToolStripPanelRow.ToolStripPanelRowControlCollection.GetControl(Int32 index) in /_/src/System.Windows.Forms/src/System/Windows/Forms/ToolStripPanelRow.ToolStripPanelRowControlCollection.cs:line 156
at System.Windows.Forms.ToolStripPanelRow.HorizontalRowManager.JoinRow(ToolStrip toolStripToDrag, Point locationToDrag) in /_/src/System.Windows.Forms/src/System/Windows/Forms/ToolStripPanelRow.HorizontalRowManager.cs:line 448
at System.Windows.Forms.ToolStripPanel.MoveInsideContainer(ToolStrip toolStripToDrag, Point clientLocation) in /_/src/System.Windows.Forms/src/System/Windows/Forms/ToolStripPanel.cs:line 1009
at System.Windows.Forms.ToolStripPanel.Join(ToolStrip toolStripToDrag, Point location) in /_/src/System.Windows.Forms/src/System/Windows/Forms/ToolStripPanel.cs:line 807
at System.Windows.Forms.ToolStripPanel.JoinControls(Boolean forceLayout) in /_/src/System.Windows.Forms/src/System/Windows/Forms/ToolStripPanel.cs:line 673
at System.Windows.Forms.ToolStripPanel.EndInit() in /_/src/System.Windows.Forms/src/System/Windows/Forms/ToolStripPanel.cs:line 388
at System.Windows.Forms.Control.ResumeLayout(Boolean performLayout) in /_/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs:line 10018
at TopToolStripPanelDemo.Form1.InitializeComponent() in E:\Demos\TopToolStripPanelDemo\TopToolStripPanelDemo\Form1.Designer.cs:line 80
at TopToolStripPanelDemo.Form1..ctor() in E:\Demos\TopToolStripPanelDemo\TopToolStripPanelDemo\Form1.cs:line 7
at TopToolStripPanelDemo.Program.Main() in E:\Demos\TopToolStripPanelDemo\TopToolStripPanelDemo\Program.cs:line 14
Findings
- If we keep the ToolStrip controls in default vertical location relationship, it works fine. Once we drag any of them to change the location, the app will get above exception.
- When adding 2 MenuStrip controls in ToolStripContainer doesn’t have this issue.
Issue Analytics
- State:
- Created 4 months ago
- Comments:11 (10 by maintainers)

Top Related StackOverflow Question
Verified this issue with dotnet-sdk-8.0.100-preview.6.23303.5, it has been fixed. Thanks.
Fixed by https://github.com/dotnet/winforms/pull/9131