question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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:

  1. Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.5.23264.1: Fail
  2. Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.4.23259.1: Pass
  3. 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:

  1. 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"
      }
    ]
  1. 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

  1. 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.
  2. When adding 2 MenuStrip controls in ToolStripContainer doesn’t have this issue.

@dotnet-actwx-bot @dotnet/compat

Issue Analytics

  • State:closed
  • Created 4 months ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
Junjun-zhaocommented, Jun 5, 2023

Verified this issue with dotnet-sdk-8.0.100-preview.6.23303.5, it has been fixed. Thanks.

1reaction
Tanya-Solyanikcommented, May 31, 2023
Read more comments on GitHub >

github_iconTop Results From Across the Web

Extend test for pr#9164 (#9215) · dotnet/winforms@4aa5492
[8.0.100-preview.5.23264.1] System.IndexOutOfRangeException thrown when ToolStrips Location is not using default Location in ToolStripContainer #6722.
Read more >
Issues - winforms - .NET Platform - Repos
[8.0.100-preview.5.23264.1] System.IndexOutOfRangeException thrown when ToolStrips Location is not using default Location in ToolStripContainer.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found