From 8c5fe3d52b60e6735dbda1c4c0321bd39fc2017e Mon Sep 17 00:00:00 2001 From: Sven Geusens Date: Thu, 27 Mar 2025 10:47:07 +0100 Subject: [PATCH] removed syslib003 & syslib0051 obsoleted code dependencies (#18827) Followed guidance in https://learn.microsoft.com/en-us/dotnet/fundamentals/syslib-diagnostics/syslibxxxx --- .../Exceptions/DataOperationException.cs | 42 ---------------- .../Exceptions/InvalidCompositionException.cs | 49 ------------------- src/Umbraco.Core/Install/InstallException.cs | 41 ---------------- src/Umbraco.Core/Semver/Semver.cs | 25 ---------- 4 files changed, 157 deletions(-) diff --git a/src/Umbraco.Core/Exceptions/DataOperationException.cs b/src/Umbraco.Core/Exceptions/DataOperationException.cs index 9acc6ded38..bb59902bca 100644 --- a/src/Umbraco.Core/Exceptions/DataOperationException.cs +++ b/src/Umbraco.Core/Exceptions/DataOperationException.cs @@ -6,7 +6,6 @@ namespace Umbraco.Cms.Core.Exceptions; /// /// /// -[Serializable] public class DataOperationException : Exception where T : Enum { @@ -57,22 +56,6 @@ public class DataOperationException : Exception : base(message) => Operation = operation; - /// - /// Initializes a new instance of the class. - /// - /// - /// The that holds the serialized object - /// data about the exception being thrown. - /// - /// - /// The that contains contextual - /// information about the source or destination. - /// - /// info - protected DataOperationException(SerializationInfo info, StreamingContext context) - : base(info, context) => - Operation = (T)Enum.Parse(typeof(T), info.GetString(nameof(Operation)) ?? string.Empty); - /// /// Gets the operation. /// @@ -83,29 +66,4 @@ public class DataOperationException : Exception /// This object should be serializable to prevent a to be thrown. /// public T? Operation { get; private set; } - - /// - /// When overridden in a derived class, sets the with - /// information about the exception. - /// - /// - /// The that holds the serialized object - /// data about the exception being thrown. - /// - /// - /// The that contains contextual - /// information about the source or destination. - /// - /// info - public override void GetObjectData(SerializationInfo info, StreamingContext context) - { - if (info == null) - { - throw new ArgumentNullException(nameof(info)); - } - - info.AddValue(nameof(Operation), Operation is not null ? Enum.GetName(typeof(T), Operation) : string.Empty); - - base.GetObjectData(info, context); - } } diff --git a/src/Umbraco.Core/Exceptions/InvalidCompositionException.cs b/src/Umbraco.Core/Exceptions/InvalidCompositionException.cs index 9bc51d7b6e..86c5e77b0a 100644 --- a/src/Umbraco.Core/Exceptions/InvalidCompositionException.cs +++ b/src/Umbraco.Core/Exceptions/InvalidCompositionException.cs @@ -8,7 +8,6 @@ namespace Umbraco.Cms.Core.Exceptions; /// The exception that is thrown when a composition is invalid. /// /// -[Serializable] public class InvalidCompositionException : Exception { /// @@ -77,26 +76,6 @@ public class InvalidCompositionException : Exception { } - /// - /// Initializes a new instance of the class. - /// - /// - /// The that holds the serialized object - /// data about the exception being thrown. - /// - /// - /// The that contains contextual - /// information about the source or destination. - /// - protected InvalidCompositionException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - ContentTypeAlias = info.GetString(nameof(ContentTypeAlias)); - AddedCompositionAlias = info.GetString(nameof(AddedCompositionAlias)); - PropertyTypeAliases = (string[]?)info.GetValue(nameof(PropertyTypeAliases), typeof(string[])); - PropertyGroupAliases = (string[]?)info.GetValue(nameof(PropertyGroupAliases), typeof(string[])); - } - /// /// Gets the content type alias. /// @@ -129,34 +108,6 @@ public class InvalidCompositionException : Exception /// public string[]? PropertyGroupAliases { get; } - /// - /// When overridden in a derived class, sets the with - /// information about the exception. - /// - /// - /// The that holds the serialized object - /// data about the exception being thrown. - /// - /// - /// The that contains contextual - /// information about the source or destination. - /// - /// info - public override void GetObjectData(SerializationInfo info, StreamingContext context) - { - if (info == null) - { - throw new ArgumentNullException(nameof(info)); - } - - info.AddValue(nameof(ContentTypeAlias), ContentTypeAlias); - info.AddValue(nameof(AddedCompositionAlias), AddedCompositionAlias); - info.AddValue(nameof(PropertyTypeAliases), PropertyTypeAliases); - info.AddValue(nameof(PropertyGroupAliases), PropertyGroupAliases); - - base.GetObjectData(info, context); - } - private static string FormatMessage(string contentTypeAlias, string? addedCompositionAlias, string[] propertyTypeAliases, string[] propertyGroupAliases) { var sb = new StringBuilder(); diff --git a/src/Umbraco.Core/Install/InstallException.cs b/src/Umbraco.Core/Install/InstallException.cs index fcb878c677..e15a0aac0a 100644 --- a/src/Umbraco.Core/Install/InstallException.cs +++ b/src/Umbraco.Core/Install/InstallException.cs @@ -6,7 +6,6 @@ namespace Umbraco.Cms.Core.Install; /// Used for steps to be able to return a JSON structure back to the UI. /// /// -[Serializable] public class InstallException : Exception { /// @@ -61,21 +60,6 @@ public class InstallException : Exception { } - /// - /// Initializes a new instance of the class. - /// - /// - /// The that holds the serialized object - /// data about the exception being thrown. - /// - /// - /// The that contains contextual - /// information about the source or destination. - /// - protected InstallException(SerializationInfo info, StreamingContext context) - : base(info, context) => - View = info.GetString(nameof(View)); - /// /// Gets the view. /// @@ -94,29 +78,4 @@ public class InstallException : Exception /// This object is not included when serializing. /// public object? ViewModel { get; private set; } - - /// - /// When overridden in a derived class, sets the with - /// information about the exception. - /// - /// - /// The that holds the serialized object - /// data about the exception being thrown. - /// - /// - /// The that contains contextual - /// information about the source or destination. - /// - /// info - public override void GetObjectData(SerializationInfo info, StreamingContext context) - { - if (info == null) - { - throw new ArgumentNullException(nameof(info)); - } - - info.AddValue(nameof(View), View); - - base.GetObjectData(info, context); - } } diff --git a/src/Umbraco.Core/Semver/Semver.cs b/src/Umbraco.Core/Semver/Semver.cs index 2b24ba5952..8d47ed4630 100644 --- a/src/Umbraco.Core/Semver/Semver.cs +++ b/src/Umbraco.Core/Semver/Semver.cs @@ -36,7 +36,6 @@ namespace Umbraco.Cms.Core.Semver #if NETSTANDARD public sealed class SemVersion : IComparable, IComparable #else - [Serializable] public sealed class SemVersion : IComparable, IComparable, ISerializable #endif { @@ -53,29 +52,6 @@ namespace Umbraco.Cms.Core.Semver RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.ExplicitCapture); #endif -#if !NETSTANDARD - /// - /// Initializes a new instance of the class. - /// - /// - /// - /// - private SemVersion(SerializationInfo info, StreamingContext context) - { - if (info == null) - { - throw new ArgumentNullException("info"); - } - - SemVersion semVersion = Parse(info.GetString("SemVersion")!); - Major = semVersion.Major; - Minor = semVersion.Minor; - Patch = semVersion.Patch; - Prerelease = semVersion.Prerelease; - Build = semVersion.Build; - } -#endif - /// /// Initializes a new instance of the class. /// @@ -525,7 +501,6 @@ namespace Umbraco.Cms.Core.Semver } #if !NETSTANDARD - [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)] public void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null)