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

Remove BinaryFormatter from DragDropLib #2608

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/Eto.Wpf/CustomControls/DragDropLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,10 @@ public static object GetManagedData(this IDataObject dataObject, string format)
if (ManagedDataStamp.Equals(guid))
{
// Stamp matched, so deserialize
BinaryFormatter formatter = new BinaryFormatter();
Type dataType = (Type)formatter.Deserialize(dataStream);
object data2 = formatter.Deserialize(dataStream);
DataContractSerializer typeSerializer = new DataContractSerializer(typeof(Type));
Type dataType = (Type)typeSerializer.ReadObject(dataStream);
DataContractSerializer objectSerializer = new DataContractSerializer(dataType);
object data2 = objectSerializer.ReadObject(dataStream);
if (data2.GetType() == dataType)
return data2;
else if (data2 is string)
Expand Down Expand Up @@ -442,9 +443,10 @@ private static void GetMediumFromObject(object data, out STGMEDIUM medium)
// we'll try type conversion. Also, we serialize the type. That way,
// during deserialization, we know which type to convert back to, if
// appropriate.
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, data.GetType());
formatter.Serialize(stream, GetAsSerializable(data));
DataContractSerializer typeSerializer = new DataContractSerializer(typeof(Type));
typeSerializer.WriteObject(stream, data.GetType());
DataContractSerializer objectSerializer = new DataContractSerializer(data.GetType());
objectSerializer.WriteObject(stream, GetAsSerializable(data));

// Now copy to an HGLOBAL
byte[] bytes = stream.GetBuffer();
Expand Down
Loading