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.

[dotnet-sdk-8.0.100-alpha.1.22619.1] System.IndexOutOfRangeException: 'Index was outside the bounds of the array.' exception thrown when OpenFileDialog.Multiselect=true

See original GitHub issue

.NET version

.NET SDK:
Version:   8.0.100-alpha.1.22619.1
Commit:    8750a90545
Runtime Environment:
OS Name:     Windows
OS Version:  10.0.19045
OS Platform: Windows
RID:         win10-x64
Base Path:   C:\Program Files\dotnet\sdk\8.0.100-alpha.1.22619.1\

Host:
 Version:      8.0.0-alpha.1.22605.1
 Architecture: x64
 Commit:       1a37caf773

.NET SDKs installed:
  8.0.100-alpha.1.22619.1 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.0-alpha.1.22615.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.0-alpha.1.22605.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 8.0.0-alpha.1.22614.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Did it work in .NET Framework?

Yes

Did it work in any of the earlier releases of .NET Core or .NET 5+?

Verify Scenarios: 1). Windows10 21H2 x64+dotnet-sdk-8.0.100-alpha.1.22621.5: Fail 2). Windows10 21H2 x64+dotnet-sdk-8.0.100-alpha.1.22619.1: Fail 3). Windows10 21H2 x64+dotnet-sdk-8.0.100-alpha.1.22616.7: Fail 4). Windows10 21H2 x64+dotnet-sdk-7.0.101: Pass

Issue description

When testing the 3rd Party Apps with .NET 8 runtime, System.IndexOutOfRangeException: ‘Index was outside the bounds of the array.’ exception thrown when OpenFileDialog.Multiselect=true

Application Name: paint.netcore, XamlViewer OS: Windows 10 21H2 CPU: X64 .NET Build Number: dotnet-sdk-8.0.100-alpha.1.22619.1

App or App Source checking at : https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1709145

Steps to reproduce

Repro steps: The machine only has 8.0 installed. And DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=2 is set.

  1. Copy paint.net app to local machine.
  2. Launch paintdotnet.exe.
  3. Click File > Open.
  4. Select one .png file, click Open button

Expected Result: The png file will be opened in paint.net app successfully.

Actual Result: Open failed and app crashed with following error (The crash log file pdncrash.1.log ): image

Minimal Repro sample: Minimal repro sample attached. OpenFileDemo.zip

  1. Create a .NET 7.0 WinForm app.
  2. Add following code in Form1.cs file:
 public Form1()
        {
            InitializeComponent();
            openFileDialog1 = new OpenFileDialog();

            selectButton = new Button()
            {
                Size = new Size(100, 20),
                Location = new Point(15, 15),
                Text = "Select file"
            };
            selectButton.Click += new EventHandler(selectButton_Click);
            Controls.Add(selectButton);
        }

        private Button selectButton;
        private OpenFileDialog openFileDialog1;


        private void selectButton_Click(object sender, EventArgs e)
        {

            openFileDialog1.Multiselect = true; //This line of code will cause the exception

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {

                    var filePath = openFileDialog1.FileName;

                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Security error.\n\nError message: {ex.Message}\n\n" +
                    $"Details:\n\n{ex.StackTrace}");
                }
            }
        }
  1. Build the project.
  2. Change the runtimeconfig to let the app run against with .NET 8.0.100-alpha.1.22619.1:
{
  "runtimeOptions": {
    "tfm": "net7.0",
    "frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "8.0.0-alpha.1.22605.1"
      },
      {
        "name": "Microsoft.WindowsDesktop.App",
        "version": "8.0.0-alpha.1.22614.1"
      }
    ]
  }
}
  1. Press F5 to launch the sample app.
  2. Click Select button and select a file to open it.

Excepted Result: No exception thrown.

Actual Result: This exception is thrown in code: image

Findings: This issue only occurs when Multiselect=true for OpenFileDialog. If we remove Multiselect=true from source code, this issue will go.

@dotnet-actwx-bot @dotnet/compat

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
Junjun-zhaocommented, Jan 30, 2023

Verified with dotnet-sdk-8.0.100-alpha.1.23077.6, this issue has been fixed.

1reaction
Nora-Zhou01commented, Jan 20, 2023

Verified with .NET SDK 8.0.100-alpha.1.23068.16 build from main branch, this issue is fixed that the png file will be opened in paint.net app successfully. open

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - What is an IndexOutOfRangeException ...
I have some code and when it executes, it throws a IndexOutOfRangeException , saying,. Index was outside the bounds of the array. What...
Read more >
IndexOutOfRangeException Class (System)
The exception that is thrown when an attempt is made to access an element of an array or collection with an index that...
Read more >
Index was outside the bounds of the array.
When I run this project on unity it keeps doing this error: IndexOutOfRangeException: Index was outside the bounds of the array. FruitSpawner+< ...
Read more >
Index was outside the bounds of the array.
Index was outside the bounds of the array. ... IndexOutOfRangeException exception is thrown as a result of developer error.
Read more >
Linq to Sharepoint throws System. ...
An exception has occurred. ExceptionType: 'IndexOutOfRangeException' ExceptionMessage: 'Index was outside the bounds of the array.
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