diff --git a/src/Avalonia.Base/Input/Platform/BinaryFormatterHelper.cs b/src/Avalonia.Base/Input/Platform/BinaryFormatterHelper.cs deleted file mode 100644 index 6e38a8afac..0000000000 --- a/src/Avalonia.Base/Input/Platform/BinaryFormatterHelper.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System; -using System.Diagnostics.CodeAnalysis; -using System.IO; -using System.Runtime.Serialization.Formatters.Binary; -using Avalonia.Compatibility; -using Avalonia.Logging; - -namespace Avalonia.Input.Platform; - -// TODO12: remove -[Obsolete("Remove in v12")] -internal static class BinaryFormatterHelper -{ - // Compatibility with WinForms + WPF... - private static ReadOnlySpan SerializedObjectGuid - => [ - // FD9EA796-3B13-4370-A679-56106BB288FB - 0x96, 0xa7, 0x9e, 0xfd, - 0x13, 0x3b, - 0x70, 0x43, - 0xa6, 0x79, 0x56, 0x10, 0x6b, 0xb2, 0x88, 0xfb - ]; - - [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "We still use BinaryFormatter for WinForms drag and drop compatibility")] - [UnconditionalSuppressMessage("Trimming", "IL3050", Justification = "We still use BinaryFormatter for WinForms drag and drop compatibility")] - public static byte[]? TrySerializeUsingBinaryFormatter(object data, DataFormat dataFormat) - { - if (!OperatingSystemEx.IsWindows()) - return null; - - Logger.TryGet(LogEventLevel.Warning, LogArea.Win32Platform)?.Log( - null, - "Using BinaryFormatter to serialize data format {Format}. This won't be supported in Avalonia v12. Prefer passing a byte[] or Stream instead.", - dataFormat); - - var stream = new MemoryStream(); - var serializedGuid = SerializedObjectGuid; - -#if NET6_0_OR_GREATER - stream.Write(serializedGuid); -#else - stream.Write(serializedGuid.ToArray(), 0, serializedGuid.Length); -#endif - -#pragma warning disable SYSLIB0011 // Type or member is obsolete - new BinaryFormatter().Serialize(stream, data); -#pragma warning restore SYSLIB0011 // Type or member is obsolete - - return stream.GetBuffer(); - } - - [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "We still use BinaryFormatter for WinForms drag and drop compatibility")] - [UnconditionalSuppressMessage("Trimming", "IL3050", Justification = "We still use BinaryFormatter for WinForms drag and drop compatibility")] - public static object? TryDeserializeUsingBinaryFormatter(byte[]? bytes) - { - var serializedObjectGuid = SerializedObjectGuid; - - // Our Win32 backend used to automatically serialize/deserialize objects using the BinaryFormatter. - // Only keep that behavior for compatibility with IDataObject. - if (OperatingSystemEx.IsWindows() && bytes is not null && bytes.AsSpan().StartsWith(serializedObjectGuid)) - { - using var stream = new MemoryStream(bytes); - stream.Position = serializedObjectGuid.Length; - -#pragma warning disable SYSLIB0011 // Type or member is obsolete - return new BinaryFormatter().Deserialize(stream); -#pragma warning restore SYSLIB0011 // Type or member is obsolete - } - - return null; - } -} diff --git a/src/Avalonia.Base/Input/Platform/Clipboard.cs b/src/Avalonia.Base/Input/Platform/Clipboard.cs index 6810851775..0d961cde3e 100644 --- a/src/Avalonia.Base/Input/Platform/Clipboard.cs +++ b/src/Avalonia.Base/Input/Platform/Clipboard.cs @@ -75,9 +75,7 @@ internal sealed class Clipboard(IClipboardImpl clipboardImpl) : IClipboard .ToArray(); } - var typedFormat = DataFormat.CreateBytesPlatformFormat(format); - var bytes = await dataTransfer.TryGetValueAsync(typedFormat).ConfigureAwait(false); - return BinaryFormatterHelper.TryDeserializeUsingBinaryFormatter(bytes) ?? bytes; + return null; } public Task TryGetDataAsync() diff --git a/src/Avalonia.Base/Input/Platform/DataObjectToDataTransferItemWrapper.cs b/src/Avalonia.Base/Input/Platform/DataObjectToDataTransferItemWrapper.cs index 656fbce996..fad3716bc7 100644 --- a/src/Avalonia.Base/Input/Platform/DataObjectToDataTransferItemWrapper.cs +++ b/src/Avalonia.Base/Input/Platform/DataObjectToDataTransferItemWrapper.cs @@ -1,11 +1,8 @@ using System; using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.IO; -using System.Runtime.Serialization.Formatters.Binary; using System.Text; using Avalonia.Compatibility; -using Avalonia.Logging; namespace Avalonia.Input.Platform; @@ -73,7 +70,7 @@ internal sealed class DataObjectToDataTransferItemWrapper( return buffer; default: - return BinaryFormatterHelper.TrySerializeUsingBinaryFormatter(data, format); + return null; } } } diff --git a/src/Avalonia.Base/Input/Platform/DataTransferToDataObjectWrapper.cs b/src/Avalonia.Base/Input/Platform/DataTransferToDataObjectWrapper.cs index f1d6040efa..814adfc4ff 100644 --- a/src/Avalonia.Base/Input/Platform/DataTransferToDataObjectWrapper.cs +++ b/src/Avalonia.Base/Input/Platform/DataTransferToDataObjectWrapper.cs @@ -36,9 +36,7 @@ internal sealed class DataTransferToDataObjectWrapper(IDataTransfer dataTransfer .ToArray(); } - var typedFormat = DataFormat.CreateBytesPlatformFormat(dataFormat); - var bytes = DataTransfer.TryGetValue(typedFormat); - return BinaryFormatterHelper.TryDeserializeUsingBinaryFormatter(bytes) ?? bytes; + return null; } }