From 7543cbc6fe59ba66c5908544dcf206d8132619c7 Mon Sep 17 00:00:00 2001 From: Alex Zaytsev Date: Mon, 11 Mar 2024 17:50:16 +1000 Subject: [PATCH] Obsolete APIs related to BinaryFormatter --- .../Cfg/ExceptionSerializationTests.cs | 2 +- src/FluentNHibernate/Automapping/AutoMappingException.cs | 5 +++-- src/FluentNHibernate/Cfg/FluentConfigurationException.cs | 4 ++++ .../Conventions/Inspections/UnmappedPropertyException.cs | 1 + .../Infrastructure/NetStandardSerialization.cs | 3 +++ src/FluentNHibernate/Infrastructure/ResolveException.cs | 1 + src/FluentNHibernate/Infrastructure/Serialization.cs | 1 + src/FluentNHibernate/Mapping/InvalidPrefixException.cs | 5 +++-- .../MappingModel/Collections/LayeredValues.cs | 8 ++++---- .../MappingModel/Conventions/ConventionException.cs | 8 +++----- src/FluentNHibernate/MissingConstructorException.cs | 5 +++-- src/FluentNHibernate/UnknownPropertyException.cs | 6 +++++- 12 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/FluentNHibernate.Testing/Cfg/ExceptionSerializationTests.cs b/src/FluentNHibernate.Testing/Cfg/ExceptionSerializationTests.cs index edc6eec97..f0f87fc30 100644 --- a/src/FluentNHibernate.Testing/Cfg/ExceptionSerializationTests.cs +++ b/src/FluentNHibernate.Testing/Cfg/ExceptionSerializationTests.cs @@ -2,12 +2,12 @@ using System.IO; using System.Runtime.Serialization.Formatters.Binary; using FluentNHibernate.Cfg; -using FluentNHibernate.Utils; using NUnit.Framework; namespace FluentNHibernate.Testing.Cfg; [TestFixture] +[Obsolete("BinaryFormatter serialization is obsolete and should not be used.")] public class ExceptionSerializationTests { [Test] diff --git a/src/FluentNHibernate/Automapping/AutoMappingException.cs b/src/FluentNHibernate/Automapping/AutoMappingException.cs index 7b54673a2..0878aade1 100644 --- a/src/FluentNHibernate/Automapping/AutoMappingException.cs +++ b/src/FluentNHibernate/Automapping/AutoMappingException.cs @@ -8,8 +8,9 @@ public class AutoMappingException : Exception { public AutoMappingException(string message) : base(message) - {} + { } + [Obsolete("This API supports obsolete formatter-based serialization and will be removed in a future version")] protected AutoMappingException(SerializationInfo info, StreamingContext context) : base(info, context) - {} + { } } diff --git a/src/FluentNHibernate/Cfg/FluentConfigurationException.cs b/src/FluentNHibernate/Cfg/FluentConfigurationException.cs index 6600f121e..1bb424593 100644 --- a/src/FluentNHibernate/Cfg/FluentConfigurationException.cs +++ b/src/FluentNHibernate/Cfg/FluentConfigurationException.cs @@ -14,6 +14,7 @@ public FluentConfigurationException(string message, Exception innerException) PotentialReasons = new List(); } + [Obsolete("This API supports obsolete formatter-based serialization and will be removed in a future version")] protected FluentConfigurationException(SerializationInfo info, StreamingContext context) : base(info, context) { this.PotentialReasons = info.GetValue("PotentialReasons", typeof(List)) as List; @@ -54,10 +55,13 @@ public override string ToString() return output; } +#pragma warning disable 809 [SecurityCritical] + [Obsolete("This API supports obsolete formatter-based serialization and will be removed in a future version")] public override void GetObjectData(SerializationInfo info, StreamingContext context) { base.GetObjectData(info, context); info.AddValue("PotentialReasons", PotentialReasons, typeof(List)); } +#pragma warning restore 809 } diff --git a/src/FluentNHibernate/Conventions/Inspections/UnmappedPropertyException.cs b/src/FluentNHibernate/Conventions/Inspections/UnmappedPropertyException.cs index 6b51c99ff..18185f109 100644 --- a/src/FluentNHibernate/Conventions/Inspections/UnmappedPropertyException.cs +++ b/src/FluentNHibernate/Conventions/Inspections/UnmappedPropertyException.cs @@ -10,6 +10,7 @@ public UnmappedPropertyException(Type type, string name) : base("Unmapped property '" + name + "' on type '" + type.Name + "'") {} + [Obsolete("This API supports obsolete formatter-based serialization and will be removed in a future version")] protected UnmappedPropertyException(SerializationInfo info, StreamingContext context) : base(info, context) {} } diff --git a/src/FluentNHibernate/Infrastructure/NetStandardSerialization.cs b/src/FluentNHibernate/Infrastructure/NetStandardSerialization.cs index d948ce6d3..7d45ca85c 100644 --- a/src/FluentNHibernate/Infrastructure/NetStandardSerialization.cs +++ b/src/FluentNHibernate/Infrastructure/NetStandardSerialization.cs @@ -12,6 +12,7 @@ namespace FluentNHibernate.Infrastructure; /// public static class NetStandardSerialization { + [Obsolete("This API supports obsolete formatter-based serialization and will be removed in a future version")] public sealed class TypeSerializationSurrogate : ISurrogateProvider { public void GetObjectData(object obj, SerializationInfo info, StreamingContext context) @@ -55,6 +56,7 @@ public object GetRealObject(StreamingContext context) } } + [Obsolete("This API supports obsolete formatter-based serialization and will be removed in a future version")] public sealed class MemberInfoSerializationSurrogate : ISurrogateProvider { public void GetObjectData(object obj, SerializationInfo info, StreamingContext context) => @@ -166,6 +168,7 @@ public object GetRealObject(StreamingContext context) } } + [Obsolete("This API supports obsolete formatter-based serialization and will be removed in a future version")] public sealed class SurrogateSelector : ISurrogateSelector { private readonly ISurrogateProvider _typeSerializationProvider; diff --git a/src/FluentNHibernate/Infrastructure/ResolveException.cs b/src/FluentNHibernate/Infrastructure/ResolveException.cs index 9fa9d8764..5ba9de444 100644 --- a/src/FluentNHibernate/Infrastructure/ResolveException.cs +++ b/src/FluentNHibernate/Infrastructure/ResolveException.cs @@ -10,6 +10,7 @@ public ResolveException(Type type) : base("Unable to resolve dependency: '" + type.FullName + "'") {} + [Obsolete("This API supports obsolete formatter-based serialization and will be removed in a future version")] protected ResolveException(SerializationInfo info, StreamingContext context) : base(info, context) {} } diff --git a/src/FluentNHibernate/Infrastructure/Serialization.cs b/src/FluentNHibernate/Infrastructure/Serialization.cs index b9024c9d3..769c30a01 100644 --- a/src/FluentNHibernate/Infrastructure/Serialization.cs +++ b/src/FluentNHibernate/Infrastructure/Serialization.cs @@ -9,6 +9,7 @@ public static class Serialization /// Extend with a "tester" method used by . /// Reference Via: https://github.com/CXuesong/BotBuilder.Standard/blob/netcore20%2Bnet45/CSharp/Library/Microsoft.Bot.Builder/Fibers/NetStandardSerialization.cs /// + [Obsolete("This API supports obsolete formatter-based serialization and will be removed in a future version")] public interface ISurrogateProvider : ISerializationSurrogate { /// diff --git a/src/FluentNHibernate/Mapping/InvalidPrefixException.cs b/src/FluentNHibernate/Mapping/InvalidPrefixException.cs index 506d6f6c0..c18de148d 100644 --- a/src/FluentNHibernate/Mapping/InvalidPrefixException.cs +++ b/src/FluentNHibernate/Mapping/InvalidPrefixException.cs @@ -10,8 +10,9 @@ namespace FluentNHibernate.Mapping; public class InvalidPrefixException : Exception { public InvalidPrefixException(string message) : base(message) - {} + { } + [Obsolete("This API supports obsolete formatter-based serialization and will be removed in a future version")] protected InvalidPrefixException(SerializationInfo info, StreamingContext context) : base(info, context) - {} + { } } diff --git a/src/FluentNHibernate/MappingModel/Collections/LayeredValues.cs b/src/FluentNHibernate/MappingModel/Collections/LayeredValues.cs index f75c5e1f7..f06f73a1d 100644 --- a/src/FluentNHibernate/MappingModel/Collections/LayeredValues.cs +++ b/src/FluentNHibernate/MappingModel/Collections/LayeredValues.cs @@ -8,9 +8,9 @@ namespace FluentNHibernate.MappingModel.Collections; public class LayeredValues : Dictionary { public LayeredValues() - {} + { } - protected LayeredValues(SerializationInfo info, StreamingContext context) - : base(info, context) - {} + [Obsolete("This API supports obsolete formatter-based serialization and will be removed in a future version")] + protected LayeredValues(SerializationInfo info, StreamingContext context) : base(info, context) + { } } diff --git a/src/FluentNHibernate/MappingModel/Conventions/ConventionException.cs b/src/FluentNHibernate/MappingModel/Conventions/ConventionException.cs index e3650a0b4..3bea5a204 100644 --- a/src/FluentNHibernate/MappingModel/Conventions/ConventionException.cs +++ b/src/FluentNHibernate/MappingModel/Conventions/ConventionException.cs @@ -13,11 +13,9 @@ public ConventionException(string message, object conventionTarget) : base(messa this.conventionTarget = conventionTarget; } - protected ConventionException( - SerializationInfo info, - StreamingContext context) : base(info, context) - { - } + [Obsolete("This API supports obsolete formatter-based serialization and will be removed in a future version")] + protected ConventionException(SerializationInfo info, StreamingContext context) : base(info, context) + { } public object ConventionTarget { diff --git a/src/FluentNHibernate/MissingConstructorException.cs b/src/FluentNHibernate/MissingConstructorException.cs index 9296b8dc6..2887b1ae4 100644 --- a/src/FluentNHibernate/MissingConstructorException.cs +++ b/src/FluentNHibernate/MissingConstructorException.cs @@ -8,8 +8,9 @@ public class MissingConstructorException : Exception { public MissingConstructorException(Type type) : base("'" + type.AssemblyQualifiedName + "' is missing a parameterless constructor.") - {} + { } + [Obsolete("This API supports obsolete formatter-based serialization and will be removed in a future version")] protected MissingConstructorException(SerializationInfo info, StreamingContext context) : base(info, context) - {} + { } } diff --git a/src/FluentNHibernate/UnknownPropertyException.cs b/src/FluentNHibernate/UnknownPropertyException.cs index 02bc62dd5..cd713eae3 100644 --- a/src/FluentNHibernate/UnknownPropertyException.cs +++ b/src/FluentNHibernate/UnknownPropertyException.cs @@ -18,17 +18,21 @@ public UnknownPropertyException(Type classType, string propertyName) public Type Type { get; private set; } + [Obsolete("This API supports obsolete formatter-based serialization and will be removed in a future version")] protected UnknownPropertyException(SerializationInfo info, StreamingContext context) : base(info, context) { this.Type = Type.GetType(info.GetString("TypeFullName")); this.Property = info.GetString("Property"); } +#pragma warning disable 809 [SecurityCritical] - public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) + [Obsolete("This API supports obsolete formatter-based serialization and will be removed in a future version")] + public override void GetObjectData(SerializationInfo info, StreamingContext context) { base.GetObjectData(info, context); info.AddValue("TypeFullName", Type.FullName); info.AddValue("Property", Property); } +#pragma warning restore 809 }