[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.
- Copy paint.net app to local machine.
- Launch paintdotnet.exe.
- Click File > Open.
- 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 ):
Minimal Repro sample: Minimal repro sample attached. OpenFileDemo.zip
- Create a .NET 7.0 WinForm app.
- 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}");
}
}
}
- Build the project.
- 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"
}
]
}
}
- Press F5 to launch the sample app.
- Click Select button and select a file to open it.
Excepted Result: No exception thrown.
Actual Result: This exception is thrown in code:
Findings: This issue only occurs when Multiselect=true for OpenFileDialog. If we remove Multiselect=true from source code, this issue will go.
Issue Analytics
- State:
- Created 9 months ago
- Comments:10 (10 by maintainers)
Top GitHub Comments
Verified with dotnet-sdk-8.0.100-alpha.1.23077.6, this issue has been fixed.
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.