Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataObject.GetData(FileContents) returns null #3026

Open
asklar opened this issue Apr 1, 2020 · 7 comments
Open

DataObject.GetData(FileContents) returns null #3026

asklar opened this issue Apr 1, 2020 · 7 comments
Labels
area-Clipboard Issues related to Clipboard 🪲 bug Product bug (most likely)
Milestone

Comments

@asklar
Copy link

asklar commented Apr 1, 2020

  • .NET Core Version:
    .NET Core SDK (reflecting any global.json):
    Version: 3.1.201
    Commit: b1768b4ae7

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19041
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.201\

Host (useful for support):
Version: 3.1.3
Commit: 4a9f85e9f8

.NET Core SDKs installed:
3.1.201 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

  • Have you experienced this same bug with .NET Framework?:
    No

Problem description:
IDataObject.GetFormats returns FileContents, but IDataObject.GetData("FileContents") returns null

Expected behavior:
Returns the file contents

Minimal repro:

@weltkante
Copy link
Contributor

I never used this particular format myself so I can't guess which application you might have used. You'll probably have to be more specific in how to repro, since DataObject content is highly dependent on how the source application presents it data.

@asklar
Copy link
Author

asklar commented Apr 1, 2020

I never used this particular format myself so I can't guess which application you might have used. You'll probably have to be more specific in how to repro, since DataObject content is highly dependent on how the source application presents it data.

Select any file in File Explorer, ctrl+C
The available formats are:
Shell IDList Array, DataObjectAttributes, DataObjectAttributesRequiringElevation, Shell Object Offsets, Preferred DropEffect, AsyncFlag, FileDrop, FileNameW, FileName, FileContents, FileGroupDescriptorW

However, the FileContents format returns null.

@weltkante
Copy link
Contributor

weltkante commented Apr 1, 2020

Thanks, I can repro the null return value, but it happens both in Desktop Framework and .NET Core.

From debugging the .NET Core implementation I see that the clipboard returns a 0x800401D3 (CLIPBRD_E_BAD_DATA) exception when reading the FileContents data. From what I can tell this is either a bug in Windows or the source application (which would be explorer) and I doubt there's anything WinForms can do if the clipboard source doesn't provide data for a format (even if it announced it had data it can still fail to deliver it, or deliver it in a format WinForms doesn't understand)

I tried various different files in case this was file-dependent but I could not get it to work, neither in Desktop Framework nor in .NET Core. Do you have a scenario which works for you in Desktop Framework? because you said

Have you experienced this same bug with .NET Framework?: No

@RussKie RussKie added the 📭 waiting-author-feedback The team requires more information from the author label Apr 1, 2020
@RussKie RussKie added this to the Future milestone Apr 2, 2020
@asklar
Copy link
Author

asklar commented Apr 17, 2020

I've confirmed the "bad data" is actually a .net bug. .net is probably not using the lIndex property to indicate which index it wants. -1 is an invalid index (which is what's used in other clipformats).
In fact I'm able to get the data from explorer in my C# app by using p/invoke.

@ghost ghost removed 📭 waiting-author-feedback The team requires more information from the author 💤 no-recent-activity labels Apr 17, 2020
@dotnet dotnet deleted a comment Apr 20, 2020
@RussKie
Copy link
Member

RussKie commented Apr 20, 2020

Nice! Do you have a fix suggestion?

@RussKie RussKie added the 🪲 bug Product bug (most likely) label Apr 20, 2020
@asklar
Copy link
Author

asklar commented Apr 20, 2020

Nice! Do you have a fix suggestion?

@RussKie Yeah I have a full implementation of clipboard APIs - including metafiles, EMF and file streams, here:
https://github.com/asklar/clipview

Specifically see https://github.com/asklar/clipview/blob/master/src/Clipboard/DataObject.cs the parts about FileContents and FileGroupDescriptor (DataObject.InternalGetData).

@RussKie RussKie added the area-Clipboard Issues related to Clipboard label May 5, 2022
@JhonnyPala
Copy link

JhonnyPala commented Nov 11, 2022

Hello world, I have a question.
I need to copy one or more files from RDP using clipboard. Pressing Ctrl+C on remote PC affects the local clipboard and vice-versa: FileGroupDescriptorW is populated correctly but FileContents contains only the content of the first file.

Analyzing the memory with HxD on the local PC, after having selected 3 files and pressed Ctrl+C on remote PC and having called GetDataObject() on local PC, I saw that there was no trace of the other file's contents adjoining the first.

I'm talking about 3 files: PIANURA.txt, COLLINA.txt, MONTAGNA.txt; the content is the same as the name, minus the .txt extension.
This is what I got by loading all the data (UTF-8 encoding), according to the GetFormats function:

[49344]FileGroupDescriptorW: [lenght: 1780] -> ����d@���������������������������������� �������������������ܑ/U������������P�I�A�N�U�R�A�.�t�x�t�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������d@���������������������������������� ����������������������P������������C�O�L�L�I�N�A�.�t�x�t�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������d@���������������������������������� ���������������������N������������M�O�N�T�A�G�N�A�.�t�x�t�����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
[49279]FileContents: [lenght: 7] -> PIANURA
[49349]Preferred DropEffect: [lenght: 4] -> ����
[49475]CanIncludeInClipboardHistory: [lenght: 4] -> ����
[49474]CanUploadToCloudClipboard: [lenght: 4] -> ����

Does anyone have experience with this stuff?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Clipboard Issues related to Clipboard 🪲 bug Product bug (most likely)
Projects
None yet
Development

No branches or pull requests

4 participants