DataObject.GetData(DataFormats.FileDrop) raises an exception when trying to get a long-path file
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
### Description
An error occurs when I try to accept a long path file (>256 characters?) from Explorer by drag and drop.
`DataObject.GetData(DataFormats.FileDrop)`
The data area passed to a system call is too small. (0x8007007A)
### Reproduction Steps
#### 1. Prepare a long-path file.
For example, a folder with a path length of 240 characters is created by creating a folder and copying a file with a 50-character filename into it.
#### 2. WPF to accept file drops and use the following method to retrieve FileDrop data.
``` cs
string[]? GetFileDrop(System.Windows.DataObject data)
{
if (data.GetDataPresent(DataFormats.FileDrop))
{
return (string[])data.GetData(DataFormats.FileDrop);
}
else
{
return null;
}
}
```
#### 3. Dropping a long-path file from Explorer to this app will cause an exception.
### Expected behavior
Even long-path files receive drops without problems.
### Actual behavior
Error message:
```
例外がスローされました: 'System.Runtime.InteropServices.COMException' (PresentationCore.dll の中)
システム コールに渡されるデータ領域が小さすぎます。 (0x8007007A)
```
Stack trace:
```
[マネージドからネイティブへの移行]
PresentationCore.dll!System.Windows.DataObject.OleConverter.GetDataFromOleHGLOBAL(string format, System.Runtime.InteropServices.ComTypes.DVASPECT aspect, int index) 不明
PresentationCore.dll!System.Windows.DataObject.OleConverter.GetData(string format, bool autoConvert, System.Runtime.InteropServices.ComTypes.DVASPECT aspect, int index) 不明
PresentationCore.dll!System.Windows.DataObject.GetData(string format, bool autoConvert) 不明
ClipboardWatch.dll!ClipboardWatch.MainWindow.GetFileDrop(System.Windows.DataObject data) 行 93 C#
:
```
----
The error also occurs via the clipboard.
The error message is different, but the stack trace is the same.
```
例外がスローされました: 'System.Runtime.InteropServices.COMException' (PresentationCore.dll の中)
クリップボードのデータが無効です (0x800401D3 (CLIPBRD_E_BAD_DATA))
```
### Regression?
_No response_
### Known Workarounds
_No response_
### Impact
_No response_
### Configuration
- .NET9
- Windows10, x64
### Other information
I found that `ReadFileListFromHandle()` in `PresentationCore/System/Windows/dataobject.cs` allocates a buffer with MAX_PATH. This may have something to do with it.
Contributor guide
Assessment
This issue has not been assessed yet.