diff --git a/src/Common/src/CoreLib/System/Text/DecoderReplacementFallback.cs b/src/Common/src/CoreLib/System/Text/DecoderReplacementFallback.cs index 1dc41d8d229b..7147b3ea0a28 100644 --- a/src/Common/src/CoreLib/System/Text/DecoderReplacementFallback.cs +++ b/src/Common/src/CoreLib/System/Text/DecoderReplacementFallback.cs @@ -3,13 +3,16 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; +using System.Runtime.Serialization; namespace System.Text { #if MONO [System.Serializable] -#endif + public sealed class DecoderReplacementFallback : DecoderFallback, ISerializable +#else public sealed class DecoderReplacementFallback : DecoderFallback +#endif { // Our variables private String _strDefault; @@ -19,6 +22,16 @@ public DecoderReplacementFallback() : this("?") { } +#if MONO + internal DecoderReplacementFallback(SerializationInfo info, StreamingContext context) + { + try { _strDefault = info.GetString("strDefault"); } // for old mono and .NET 4.x + catch { _strDefault = info.GetString("_strDefault"); } + } + + void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) => info.AddValue("strDefault", _strDefault); +#endif + public DecoderReplacementFallback(String replacement) { if (replacement == null) diff --git a/src/Common/src/CoreLib/System/Text/EncoderReplacementFallback.cs b/src/Common/src/CoreLib/System/Text/EncoderReplacementFallback.cs index ff97fbaf41e0..eac4c9e3a8cd 100644 --- a/src/Common/src/CoreLib/System/Text/EncoderReplacementFallback.cs +++ b/src/Common/src/CoreLib/System/Text/EncoderReplacementFallback.cs @@ -5,13 +5,16 @@ using System; using System.Runtime; using System.Diagnostics; +using System.Runtime.Serialization; namespace System.Text { #if MONO [Serializable] -#endif + public sealed class EncoderReplacementFallback : EncoderFallback, ISerializable +#else public sealed class EncoderReplacementFallback : EncoderFallback +#endif { // Our variables private String _strDefault; @@ -21,6 +24,16 @@ public EncoderReplacementFallback() : this("?") { } +#if MONO + internal EncoderReplacementFallback(SerializationInfo info, StreamingContext context) + { + try { _strDefault = info.GetString("strDefault"); } // for old mono and .NET 4.x + catch { _strDefault = info.GetString("_strDefault"); } + } + + void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) => info.AddValue("strDefault", _strDefault); +#endif + public EncoderReplacementFallback(String replacement) { // Must not be null