Repository navigation
Description
.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.
@dotnet-actwx-bot @dotnet/compat
Activity
elachlan commentedon Jan 5, 2023
There is a few issues here:
The FileName property getter doesn't check if there are items in the
_fileNamesarray.winforms/src/System.Windows.Forms/src/System/Windows/Forms/FileDialog.cs
Lines 161 to 172 in 62edc1a
Fix:
The other issue is that
_fileNamesshould have an item in it, but it doesn't. It is set inDoFileOk. Which conditionally set the _fileNames based on theOFN_ALLOWMULTISELECTflag.winforms/src/System.Windows.Forms/src/System/Windows/Forms/FileDialog.cs
Lines 402 to 404 in 62edc1a
I am unsure how we can interact with a filedialog in an integration test so we can avoid regressions. Would manual testing be ok?
dreddy-work commentedon Jan 6, 2023
Do you know which commit caused this regression? Is this from CSWin32 changes?
elachlan commentedon Jan 6, 2023
I haven't bisected it. But I suspect its caused by #7933
That refactored
GetMultiselectFilesandDoFileOk. I am having issues with debug not working in VS preview, otherwise I would have tracked it down.dreddy-work commentedon Jan 6, 2023
Okay. Thank you.
FYI - Latest SDK install should unblock you from debugging.
merriemcgaw commentedon Jan 10, 2023
@JeremyKuhne could you take a look at this one when you have a chance? I'd like to get it serviced sooner rather than later.
elachlan commentedon Jan 10, 2023
@merriemcgaw I don't think its affecting 7.x just 8.x.
JeremyKuhne commentedon Jan 13, 2023
@elachlan I fixed the issue and found a way to automate the regression test.
Nora-Zhou01 commentedon 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.

Junjun-zhao commentedon Jan 30, 2023
Verified with dotnet-sdk-8.0.100-alpha.1.23077.6, this issue has been fixed.
John-Qiao commentedon Feb 13, 2023
Verified with .NET 8 Preview 1 TP build: .NET 8.0.100-preview.1.23108.10, issue was fixed as same as above test result.