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

Clipboard.SetDataObject fails for user defined clipboard formats #415

JoeErickson opened this Issue Feb 7, 2019 · 0 comments


None yet
3 participants
Copy link

JoeErickson commented Feb 7, 2019

I have a fix and XUnit test which I will issue a pull request for shortly.

  • .NET Core Version: 3.0.100-preview-010226
  • Have you experienced this same bug with .NET Framework?: No

Problem description:

While testing SpreadsheetGear for Windows Forms on .NET Core 3 we found that Clipboard.SetDataObject fails for custom clipboard types. This is apparently due to Span work in this checkin which removed the necessary 'stream.Position = 0' before reading from the stream:

Actual behavior:

Uninitialized data gets written to the clipboard.

Expected behavior:

.NET objects get serialized to clipboard.

Minimal repro:
private void DataObject_CustomFormats()
var myTextFormat = "MyTextFormat";
var myBlobFormat = "MyBlobFormat";
var guid = Guid.NewGuid();
var myText = guid.ToString();
var myBlob = new System.IO.MemoryStream(guid.ToByteArray());
var unicodeText = "Euro char: \u20AC";
var data = new System.Windows.Forms.DataObject();
data.SetData(myTextFormat, myText);
data.SetData(myBlobFormat, myBlob);
var copiedDataObject = System.Windows.Forms.Clipboard.GetDataObject();
var copiedText = copiedDataObject.GetData(myTextFormat) as string;
var copiedBlob = copiedDataObject.GetData(myBlobFormat) as System.IO.MemoryStream;
var copiedUnicodeText = System.Windows.Forms.Clipboard.GetText();
Assert.Equal(copiedText, myText);
Assert.Equal(copiedBlob.Length, myBlob.Length);
Assert.Equal(new Guid(copiedBlob.ToArray()), guid);
Assert.Equal(copiedUnicodeText, unicodeText);

@merriemcgaw merriemcgaw added the bug label Feb 8, 2019

@merriemcgaw merriemcgaw added this to the 3.0 milestone Feb 8, 2019

Tanya-Solyanik added a commit that referenced this issue Feb 20, 2019

Fixed Clipboard.SetDataObject to work with custom formats #415 (#416)
fixes #415

While testing SpreadsheetGear for Windows Forms on .NET Core 3 we found that Clipboard.SetDataObject writes uninitialized data to the clipboard instead of serialized .NET objects.

This bug is apparently a regression from Span<T> work in 37abb3a.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment