diff --git a/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/DeserializingResourceReader.cs b/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/DeserializingResourceReader.cs index 2d626423506df..9ce7d85ed9eba 100644 --- a/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/DeserializingResourceReader.cs +++ b/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/DeserializingResourceReader.cs @@ -3,6 +3,7 @@ using System.ComponentModel; using System.IO; +using System.Resources.Extensions.BinaryFormat; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; @@ -12,11 +13,6 @@ public partial class DeserializingResourceReader { private bool _assumeBinaryFormatter; -// Issue https://github.com/dotnet/runtime/issues/39292 tracks finding an alternative to BinaryFormatter -#pragma warning disable SYSLIB0011 - private BinaryFormatter? _formatter; -#pragma warning restore SYSLIB0011 - private bool ValidateReaderType(string readerType) { // our format? @@ -41,12 +37,13 @@ private bool ValidateReaderType(string readerType) #pragma warning disable SYSLIB0011 private object ReadBinaryFormattedObject() { - _formatter ??= new BinaryFormatter() - { - Binder = new UndoTruncatedTypeNameSerializationBinder() - }; + BinaryFormattedObject binaryFormattedObject = new BinaryFormattedObject(_store.BaseStream, + new BinaryFormattedObject.Options() + { + Binder = new UndoTruncatedTypeNameSerializationBinder() + }); - return _formatter.Deserialize(_store.BaseStream); + return binaryFormattedObject.Deserialize(); } #pragma warning restore SYSLIB0011