Only Unwrap If Given IDataObject#12738
Conversation
c428833 to
a4882d5
Compare
src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataObjectTests.cs
Show resolved
Hide resolved
|
It isn't COM giving us back the other data types in this case. It is our own implementation. The native Switching to The mitigation here is when we're wrapping arbitrary types (objects that don't already derive from the managed |
Fixes #12665
In .NET 9, we had switched to leveraging cswin32 and ComWrappers for our OLE interop. During this we discovered that switching from built-in COM to ComWrappers took away the ability to automatically cast native pointers back to their original managed object when round tripping through native code. In order to remedy this, we updated to wrap the data on clipboard set and unwrap the object retrieved from the clipboard manually before returning it to get the original data.
While doing this, we had missed the fact that the native IDataObject interface doesn't have the concept of explicit autoConvert. Meaning that when calling our Clipboard APIs with autoConvert = false, it will effectively be ignored and produce same results as autoConvert = true if we're calling to a native IDataObject interface. In .NET 9, since we always unwrap the object retrieved from the clipboard to get our completely managed DataObject, we lost this behavior for types that don't already derive from managed IDataObject.
To fix this, the change here is that when we wrap types that don't already derive from the managed IDataObject, we won't automatically unwrap to the wrapping DataObject we created.
Changes also includes adding more tests to capture behavior and minor optimization with not wrapping twice
Microsoft Reviewers: Open in CodeFlow