Skip to content

Commit

Permalink
Remove BinaryFormatter from DragDropLib
Browse files Browse the repository at this point in the history
  • Loading branch information
jonko0493 committed Jan 14, 2024
1 parent 51e1798 commit b5056a9
Showing 1 changed file with 8 additions and 6 deletions.
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

0 comments on commit b5056a9

Please sign in to comment.