From fade67bdb45f3363ed33e09c5a1c8b8812b1a305 Mon Sep 17 00:00:00 2001 From: Ronald Barendse Date: Fri, 19 Jul 2019 10:22:44 +0200 Subject: [PATCH] Updated exceptions with SerializableAttribute and constructor --- .../Collections/ObservableDictionary.cs | 66 +++++- .../LightInject/LightInjectException.cs | 59 +++++- src/Umbraco.Core/Composing/TypeLoader.cs | 40 +++- .../ArgumentNullOrEmptyException.cs | 36 +++- .../Exceptions/AuthorizationException.cs | 31 +++ .../Exceptions/BootFailedException.cs | 41 +++- .../Exceptions/ConnectionException.cs | 39 +++- .../Exceptions/DataOperationException.cs | 79 +++++++- .../Exceptions/InvalidCompositionException.cs | 124 ++++++++++-- .../Exceptions/WontImplementException.cs | 32 ++- src/Umbraco.Core/IO/FileSecurityException.cs | 41 +++- .../Migrations/DataLossException.cs | 41 +++- .../IncompleteMigrationExpressionException.cs | 33 ++- .../Persistence/EntityNotFoundException.cs | 82 ++++++-- .../RetryLimitExceededException.cs | 36 ++-- src/Umbraco.Web/Install/InstallException.cs | 99 +++++++-- src/Umbraco.Web/Media/Exif/ExifExceptions.cs | 79 ++++++-- src/Umbraco.Web/Media/Exif/JPEGExceptions.cs | 188 ++++++++++++++---- .../HttpUmbracoFormRouteStringException.cs | 9 +- src/Umbraco.Web/Mvc/ModelBindingException.cs | 31 +++ 20 files changed, 993 insertions(+), 193 deletions(-) diff --git a/src/Umbraco.Core/Collections/ObservableDictionary.cs b/src/Umbraco.Core/Collections/ObservableDictionary.cs index 40269aa4eb..359fefda48 100644 --- a/src/Umbraco.Core/Collections/ObservableDictionary.cs +++ b/src/Umbraco.Core/Collections/ObservableDictionary.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using System.Runtime.Serialization; namespace Umbraco.Core.Collections { @@ -235,15 +236,76 @@ namespace Umbraco.Core.Collections #endregion + /// + /// The exception that is thrown when a duplicate key inserted. + /// + /// + /// + /// + [Serializable] internal class DuplicateKeyException : Exception { + /// + /// Gets the key. + /// + /// + /// The key. + /// + public string Key { get; } + + /// + /// Initializes a new instance of the class. + /// + public DuplicateKeyException() + { } + + /// + /// Initializes a new instance of the class. + /// + /// The key. public DuplicateKeyException(string key) - : base("Attempted to insert duplicate key \"" + key + "\" in collection.") + : this(key, null) + { } + + /// + /// Initializes a new instance of the class. + /// + /// The key. + /// The exception that is the cause of the current exception, or a null reference ( in Visual Basic) if no inner exception is specified. + public DuplicateKeyException(string key, Exception innerException) + : base("Attempted to insert duplicate key \"" + key + "\" in collection.", innerException) { Key = key; } - public string Key { get; } + /// + /// 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 DuplicateKeyException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + Key = info.GetString(nameof(Key)); + } + + /// + /// 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(Key), Key); + + base.GetObjectData(info, context); + } } } } diff --git a/src/Umbraco.Core/Composing/LightInject/LightInjectException.cs b/src/Umbraco.Core/Composing/LightInject/LightInjectException.cs index fa0aed21ca..e1344468f9 100644 --- a/src/Umbraco.Core/Composing/LightInject/LightInjectException.cs +++ b/src/Umbraco.Core/Composing/LightInject/LightInjectException.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.Serialization; using System.Text; namespace Umbraco.Core.Composing.LightInject @@ -6,20 +7,51 @@ namespace Umbraco.Core.Composing.LightInject /// /// Represents errors that occur due to LightInject. /// + /// + [Serializable] public class LightInjectException : Exception { - public LightInjectException(string message) - : base(message) - { } - - public LightInjectException(string message, Exception innerException) - : base(message, innerException) - { } - private const string LightInjectUnableToResolveType = "Unable to resolve type:"; private const string LightInjectUnresolvedDependency = "Unresolved dependency "; private const string LightInjectRequestedDependency = "[Requested dependency:"; + /// + /// Initializes a new instance of the class. + /// + public LightInjectException() + { } + + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. + public LightInjectException(string message) + : base(message) + { } + + /// + /// Initializes a new instance of the class. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, or a null reference ( in Visual Basic) if no inner exception is specified. + public LightInjectException(string message, Exception innerException) + : base(message, innerException) + { } + + /// + /// 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 LightInjectException(SerializationInfo info, StreamingContext context) + : base(info, context) + { } + + /// + /// Tries to throw the exception with additional details. + /// + /// The exception. + /// public static void TryThrow(Exception e) { var ex = e as InvalidOperationException; @@ -32,6 +64,12 @@ namespace Umbraco.Core.Composing.LightInject throw new LightInjectException(sb.ToString(), e); } + /// + /// Tries to throw the exception with additional details. + /// + /// The exception. + /// The implementing type. + /// public static void TryThrow(Exception e, Type implementingType) { var ex = e as InvalidOperationException; @@ -45,6 +83,11 @@ namespace Umbraco.Core.Composing.LightInject throw new LightInjectException(sb.ToString(), e); } + /// + /// Writes the details. + /// + /// The exception. + /// The to write the details to. private static void WriteDetails(InvalidOperationException ex, StringBuilder sb) { ex = ex.InnerException as InvalidOperationException; diff --git a/src/Umbraco.Core/Composing/TypeLoader.cs b/src/Umbraco.Core/Composing/TypeLoader.cs index fe7a561eca..9f3b4b6858 100644 --- a/src/Umbraco.Core/Composing/TypeLoader.cs +++ b/src/Umbraco.Core/Composing/TypeLoader.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; +using System.Runtime.Serialization; using System.Text; using System.Threading; using System.Web; @@ -813,11 +814,44 @@ namespace Umbraco.Core.Composing } /// - /// Represents the error that occurs when a type was not found in the cache type - /// list with the specified TypeResolutionKind. + /// Represents the error that occurs when a type was not found in the cache type list with the specified TypeResolutionKind. /// + /// + [Serializable] internal class CachedTypeNotFoundInFileException : Exception - { } + { + /// + /// Initializes a new instance of the class. + /// + public CachedTypeNotFoundInFileException() + { } + + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. + public CachedTypeNotFoundInFileException(string message) + : base(message) + { } + + /// + /// Initializes a new instance of the class. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, or a null reference ( in Visual Basic) if no inner exception is specified. + public CachedTypeNotFoundInFileException(string message, Exception innerException) + : base(message, innerException) + { } + + /// + /// 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 CachedTypeNotFoundInFileException(SerializationInfo info, StreamingContext context) + : base(info, context) + { } + } #endregion } diff --git a/src/Umbraco.Core/Exceptions/ArgumentNullOrEmptyException.cs b/src/Umbraco.Core/Exceptions/ArgumentNullOrEmptyException.cs index 90cc20c404..cf6cddd801 100644 --- a/src/Umbraco.Core/Exceptions/ArgumentNullOrEmptyException.cs +++ b/src/Umbraco.Core/Exceptions/ArgumentNullOrEmptyException.cs @@ -1,16 +1,23 @@ using System; +using System.Runtime.Serialization; namespace Umbraco.Core.Exceptions { /// - /// The exception that is thrown when a null reference, or an empty argument, - /// is passed to a method that does not accept it as a valid argument. + /// The exception that is thrown when a null reference, or an empty argument, is passed to a method that does not accept it as a valid argument. /// + /// + [Serializable] public class ArgumentNullOrEmptyException : ArgumentNullException { /// - /// Initializes a new instance of the class - /// with the name of the parameter that caused this exception. + /// Initializes a new instance of the class. + /// + public ArgumentNullOrEmptyException() + { } + + /// + /// Initializes a new instance of the class with the name of the parameter that caused this exception. /// /// The named of the parameter that caused the exception. public ArgumentNullOrEmptyException(string paramName) @@ -18,13 +25,30 @@ namespace Umbraco.Core.Exceptions { } /// - /// Initializes a new instance of the class - /// with a specified error message and the name of the parameter that caused this exception. + /// Initializes a new instance of the class with a specified error message and the name of the parameter that caused this exception. /// /// The named of the parameter that caused the exception. /// A message that describes the error. public ArgumentNullOrEmptyException(string paramName, string message) : base(paramName, message) { } + + /// + /// Initializes a new instance of the class. + /// + /// The error message that explains the reason for this exception. + /// The exception that is the cause of the current exception, or a null reference ( in Visual Basic) if no inner exception is specified. + public ArgumentNullOrEmptyException(string message, Exception innerException) + : base(message, innerException) + { } + + /// + /// Initializes a new instance of the class. + /// + /// The object that holds the serialized object data. + /// An object that describes the source or destination of the serialized data. + protected ArgumentNullOrEmptyException(SerializationInfo info, StreamingContext context) + : base(info, context) + { } } } diff --git a/src/Umbraco.Core/Exceptions/AuthorizationException.cs b/src/Umbraco.Core/Exceptions/AuthorizationException.cs index 955fec270b..b87a8da8b8 100644 --- a/src/Umbraco.Core/Exceptions/AuthorizationException.cs +++ b/src/Umbraco.Core/Exceptions/AuthorizationException.cs @@ -1,14 +1,45 @@ using System; +using System.Runtime.Serialization; namespace Umbraco.Core.Exceptions { + /// + /// The exception that is thrown when authorization failed. + /// + /// + [Serializable] public class AuthorizationException : Exception { + /// + /// Initializes a new instance of the class. + /// public AuthorizationException() { } + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. public AuthorizationException(string message) : base(message) { } + + /// + /// Initializes a new instance of the class. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, or a null reference ( in Visual Basic) if no inner exception is specified. + public AuthorizationException(string message, Exception innerException) + : base(message, innerException) + { } + + /// + /// 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 AuthorizationException(SerializationInfo info, StreamingContext context) + : base(info, context) + { } } } diff --git a/src/Umbraco.Core/Exceptions/BootFailedException.cs b/src/Umbraco.Core/Exceptions/BootFailedException.cs index c3262d26c6..e8ffe1d2e9 100644 --- a/src/Umbraco.Core/Exceptions/BootFailedException.cs +++ b/src/Umbraco.Core/Exceptions/BootFailedException.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.Serialization; using System.Text; namespace Umbraco.Core.Exceptions @@ -6,6 +7,8 @@ namespace Umbraco.Core.Exceptions /// /// An exception that is thrown if the Umbraco application cannot boot. /// + /// + [Serializable] public class BootFailedException : Exception { /// @@ -14,27 +17,47 @@ namespace Umbraco.Core.Exceptions public const string DefaultMessage = "Boot failed: Umbraco cannot run. See Umbraco's log file for more details."; /// - /// Initializes a new instance of the class with a specified error message. + /// Initializes a new instance of the class. /// - /// The message that describes the error. + public BootFailedException() + { } + + /// + /// Initializes a new instance of the class with a specified error message. + /// + /// The message that describes the error. public BootFailedException(string message) : base(message) { } /// - /// Initializes a new instance of the class with a specified error message + /// Initializes a new instance of the class with a specified error message /// and a reference to the inner exception which is the cause of this exception. /// - /// The message that describes the error. - /// The inner exception, or null. - public BootFailedException(string message, Exception inner) - : base(message, inner) + /// The message that describes the error. + /// The inner exception, or null. + public BootFailedException(string message, Exception innerException) + : base(message, innerException) { } /// - /// Rethrows a captured . + /// Initializes a new instance of the class. /// - /// The exception can be null, in which case a default message is used. + /// The that holds the serialized object data about the exception being thrown. + /// The that contains contextual information about the source or destination. + protected BootFailedException(SerializationInfo info, StreamingContext context) + : base(info, context) + { } + + /// + /// Rethrows a captured . + /// + /// The boot failed exception. + /// + /// + /// + /// The exception can be null, in which case a default message is used. + /// public static void Rethrow(BootFailedException bootFailedException) { if (bootFailedException == null) diff --git a/src/Umbraco.Core/Exceptions/ConnectionException.cs b/src/Umbraco.Core/Exceptions/ConnectionException.cs index 64fdbeee52..517d0633a0 100644 --- a/src/Umbraco.Core/Exceptions/ConnectionException.cs +++ b/src/Umbraco.Core/Exceptions/ConnectionException.cs @@ -1,12 +1,45 @@ using System; +using System.Runtime.Serialization; namespace Umbraco.Core.Exceptions { + /// + /// The exception that is thrown when a connection fails. + /// + /// + [Serializable] internal class ConnectionException : Exception { - public ConnectionException(string message, Exception innerException) : base(message, innerException) - { + /// + /// Initializes a new instance of the class. + /// + public ConnectionException() + { } - } + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. + public ConnectionException(string message) + : base(message) + { } + + /// + /// Initializes a new instance of the class. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, or a null reference ( in Visual Basic) if no inner exception is specified. + public ConnectionException(string message, Exception innerException) + : base(message, innerException) + { } + + /// + /// 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 ConnectionException(SerializationInfo info, StreamingContext context) + : base(info, context) + { } } } diff --git a/src/Umbraco.Core/Exceptions/DataOperationException.cs b/src/Umbraco.Core/Exceptions/DataOperationException.cs index 14fefcf9d3..4248377e3d 100644 --- a/src/Umbraco.Core/Exceptions/DataOperationException.cs +++ b/src/Umbraco.Core/Exceptions/DataOperationException.cs @@ -1,21 +1,94 @@ using System; +using System.Runtime.Serialization; namespace Umbraco.Core.Exceptions { + /// + /// + /// + /// + /// + [Serializable] internal class DataOperationException : Exception { + /// + /// Gets the operation. + /// + /// + /// The operation. + /// public T Operation { get; private set; } + /// + /// Initializes a new instance of the class. + /// + public DataOperationException() + { } + + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. + public DataOperationException(string message) + : base(message) + { } + + /// + /// Initializes a new instance of the class. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, or a null reference ( in Visual Basic) if no inner exception is specified. + public DataOperationException(string message, Exception innerException) + : base(message, innerException) + { } + + /// + /// Initializes a new instance of the class. + /// + /// The operation. + public DataOperationException(T operation) + : this(operation, "Data operation exception: " + operation) + { } + + /// + /// Initializes a new instance of the class. + /// + /// The operation. + /// The message. public DataOperationException(T operation, string message) : base(message) { Operation = operation; } - public DataOperationException(T operation) - : base("Data operation exception: " + 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 = operation; + Operation = (T)info.GetValue(nameof(Operation), typeof(T)); + } + + /// + /// 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); + + base.GetObjectData(info, context); } } } diff --git a/src/Umbraco.Core/Exceptions/InvalidCompositionException.cs b/src/Umbraco.Core/Exceptions/InvalidCompositionException.cs index 9d154c6a6f..684e23b020 100644 --- a/src/Umbraco.Core/Exceptions/InvalidCompositionException.cs +++ b/src/Umbraco.Core/Exceptions/InvalidCompositionException.cs @@ -1,44 +1,126 @@ using System; +using System.Runtime.Serialization; namespace Umbraco.Core.Exceptions { + /// + /// The exception that is thrown when a composition is invalid. + /// + /// + [Serializable] public class InvalidCompositionException : Exception { - public InvalidCompositionException(string contentTypeAlias, string addedCompositionAlias, string[] propertyTypeAliass) - { - ContentTypeAlias = contentTypeAlias; - AddedCompositionAlias = addedCompositionAlias; - PropertyTypeAliases = propertyTypeAliass; - } + /// + /// Gets the content type alias. + /// + /// + /// The content type alias. + /// + public string ContentTypeAlias { get; } - public InvalidCompositionException(string contentTypeAlias, string[] propertyTypeAliass) - { - ContentTypeAlias = contentTypeAlias; - PropertyTypeAliases = propertyTypeAliass; - } + /// + /// Gets the added composition alias. + /// + /// + /// The added composition alias. + /// + public string AddedCompositionAlias { get; } - public string ContentTypeAlias { get; private set; } + /// + /// Gets the property type aliases. + /// + /// + /// The property type aliases. + /// + public string[] PropertyTypeAliases { get; } - public string AddedCompositionAlias { get; private set; } + /// + /// Initializes a new instance of the class. + /// + public InvalidCompositionException() + { } - public string[] PropertyTypeAliases { get; private set; } + /// + /// Initializes a new instance of the class. + /// + /// The content type alias. + /// The property type aliases. + public InvalidCompositionException(string contentTypeAlias, string[] propertyTypeAliases) + : this(contentTypeAlias, null, propertyTypeAliases) + { } - public override string Message - { - get - { - return AddedCompositionAlias.IsNullOrWhiteSpace() + /// + /// Initializes a new instance of the class. + /// + /// The content type alias. + /// The added composition alias. + /// The property type aliases. + public InvalidCompositionException(string contentTypeAlias, string addedCompositionAlias, string[] propertyTypeAliases) + : this(addedCompositionAlias.IsNullOrWhiteSpace() ? string.Format( "ContentType with alias '{0}' has an invalid composition " + "and there was a conflict on the following PropertyTypes: '{1}'. " + "PropertyTypes must have a unique alias across all Compositions in order to compose a valid ContentType Composition.", - ContentTypeAlias, string.Join(", ", PropertyTypeAliases)) + contentTypeAlias, string.Join(", ", propertyTypeAliases)) : string.Format( "ContentType with alias '{0}' was added as a Composition to ContentType with alias '{1}', " + "but there was a conflict on the following PropertyTypes: '{2}'. " + "PropertyTypes must have a unique alias across all Compositions in order to compose a valid ContentType Composition.", - AddedCompositionAlias, ContentTypeAlias, string.Join(", ", PropertyTypeAliases)); + addedCompositionAlias, contentTypeAlias, string.Join(", ", propertyTypeAliases))) + { + ContentTypeAlias = contentTypeAlias; + AddedCompositionAlias = addedCompositionAlias; + PropertyTypeAliases = propertyTypeAliases; + } + + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. + public InvalidCompositionException(string message) + : base(message) + { } + + /// + /// Initializes a new instance of the class. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, or a null reference ( in Visual Basic) if no inner exception is specified. + public InvalidCompositionException(string message, Exception innerException) + : base(message, innerException) + { } + + /// + /// 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[])); + } + + /// + /// 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); + + base.GetObjectData(info, context); } } } diff --git a/src/Umbraco.Core/Exceptions/WontImplementException.cs b/src/Umbraco.Core/Exceptions/WontImplementException.cs index 7774bf53de..3e2765c3c2 100644 --- a/src/Umbraco.Core/Exceptions/WontImplementException.cs +++ b/src/Umbraco.Core/Exceptions/WontImplementException.cs @@ -1,27 +1,51 @@ using System; +using System.Runtime.Serialization; namespace Umbraco.Core.Exceptions { /// /// The exception that is thrown when a requested method or operation is not, and will not be, implemented. /// - /// The is to be used when some code is not implemented, + /// + /// The is to be used when some code is not implemented, /// but should eventually be implemented (i.e. work in progress) and is reported by tools such as ReSharper. /// This exception is to be used when some code is not implemented, and is not meant to be, for whatever - /// reason. + /// reason. + /// + /// + [Serializable] public class WontImplementException : NotImplementedException { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public WontImplementException() { } /// - /// Initializes a new instance of the class with a specified reason message. + /// Initializes a new instance of the class with a specified reason message. /// + /// The error message that explains the reason for the exception. public WontImplementException(string message) : base(message) { } + + /// + /// Initializes a new instance of the class. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception. If the parameter is not , the current exception is raised in a block that handles the inner exception. + public WontImplementException(string message, Exception inner) + : base(message, inner) + { } + + /// + /// 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 WontImplementException(SerializationInfo info, StreamingContext context) + : base(info, context) + { } } } diff --git a/src/Umbraco.Core/IO/FileSecurityException.cs b/src/Umbraco.Core/IO/FileSecurityException.cs index 7b4f7d2625..1bebb6d391 100644 --- a/src/Umbraco.Core/IO/FileSecurityException.cs +++ b/src/Umbraco.Core/IO/FileSecurityException.cs @@ -1,20 +1,45 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Runtime.Serialization; namespace Umbraco.Core.IO { + /// + /// The exception that is thrown when the caller does not have the required permission to access a file. + /// + /// + [Serializable] public class FileSecurityException : Exception { + /// + /// Initializes a new instance of the class. + /// public FileSecurityException() - { + { } - } + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. + public FileSecurityException(string message) + : base(message) + { } - public FileSecurityException(string message) : base(message) - { + /// + /// Initializes a new instance of the class. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, or a null reference ( in Visual Basic) if no inner exception is specified. + public FileSecurityException(string message, Exception innerException) + : base(message, innerException) + { } - } + /// + /// 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 FileSecurityException(SerializationInfo info, StreamingContext context) + : base(info, context) + { } } } diff --git a/src/Umbraco.Core/Migrations/DataLossException.cs b/src/Umbraco.Core/Migrations/DataLossException.cs index 6ff332f626..1ba10bce62 100644 --- a/src/Umbraco.Core/Migrations/DataLossException.cs +++ b/src/Umbraco.Core/Migrations/DataLossException.cs @@ -1,22 +1,45 @@ using System; +using System.Runtime.Serialization; namespace Umbraco.Core.Migrations { /// - /// Used if a migration has executed but the whole process has failed and cannot be rolled back + /// The exception that is thrown if a migration has executed, but the whole process has failed and cannot be rolled back. /// + /// + [Serializable] internal class DataLossException : Exception { - public DataLossException(string msg) - : base(msg) - { + /// + /// Initializes a new instance of the class. + /// + public DataLossException() + { } - } + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. + public DataLossException(string message) + : base(message) + { } - public DataLossException(string msg, Exception inner) - : base(msg, inner) - { + /// + /// Initializes a new instance of the class. + /// + /// The error message that explains the reason for the exception. + /// The inner exception. + public DataLossException(string message, Exception innerException) + : base(message, innerException) + { } - } + /// + /// 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 DataLossException(SerializationInfo info, StreamingContext context) + : base(info, context) + { } } } diff --git a/src/Umbraco.Core/Migrations/IncompleteMigrationExpressionException.cs b/src/Umbraco.Core/Migrations/IncompleteMigrationExpressionException.cs index 91d1838d6f..3c81e2f0e2 100644 --- a/src/Umbraco.Core/Migrations/IncompleteMigrationExpressionException.cs +++ b/src/Umbraco.Core/Migrations/IncompleteMigrationExpressionException.cs @@ -1,28 +1,49 @@ using System; +using System.Runtime.Serialization; namespace Umbraco.Core.Migrations { /// - /// Represents errors that occurs when a migration exception is not executed. + /// The exception that is thrown when a migration expression is not executed. /// /// - /// Migration expression such as Alter.Table(...).Do() *must* end with Do() else they are - /// not executed. When a non-executed expression is detected, an IncompleteMigrationExpressionException - /// is thrown. + /// Migration expressions such as Alter.Table(...).Do() must end with Do(), else they are not executed. + /// When a non-executed expression is detected, an IncompleteMigrationExpressionException is thrown. /// + /// + [Serializable] public class IncompleteMigrationExpressionException : Exception { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public IncompleteMigrationExpressionException() { } /// - /// Initializes a new instance of the class with a message. + /// Initializes a new instance of the class with a message. /// + /// The message that describes the error. public IncompleteMigrationExpressionException(string message) : base(message) { } + + /// + /// Initializes a new instance of the class. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, or a null reference ( in Visual Basic) if no inner exception is specified. + public IncompleteMigrationExpressionException(string message, Exception innerException) + : base(message, innerException) + { } + + /// + /// 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 IncompleteMigrationExpressionException(SerializationInfo info, StreamingContext context) + : base(info, context) + { } } } diff --git a/src/Umbraco.Core/Persistence/EntityNotFoundException.cs b/src/Umbraco.Core/Persistence/EntityNotFoundException.cs index e0fe778fa6..6bcf6a269d 100644 --- a/src/Umbraco.Core/Persistence/EntityNotFoundException.cs +++ b/src/Umbraco.Core/Persistence/EntityNotFoundException.cs @@ -1,38 +1,94 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Runtime.Serialization; namespace Umbraco.Core.Persistence { - // TODO: Would be good to use this exception type anytime we cannot find an entity /// - /// An exception used to indicate that an umbraco entity could not be found + /// An exception used to indicate that an Umbraco entity could not be found. /// + /// + [Serializable] public class EntityNotFoundException : Exception { + /// + /// Gets the identifier. + /// + /// + /// The identifier. + /// public object Id { get; private set; } - private readonly string _msg; - public EntityNotFoundException(object id, string msg) + /// + /// Initializes a new instance of the class. + /// + public EntityNotFoundException() + { } + + /// + /// Initializes a new instance of the class. + /// + /// The identifier. + /// The message. + public EntityNotFoundException(object id, string message) + : base(message) { Id = id; - _msg = msg; } - public EntityNotFoundException(string msg) + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. + public EntityNotFoundException(string message) + : base(message) + { } + + /// + /// Initializes a new instance of the class. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, or a null reference ( in Visual Basic) if no inner exception is specified. + public EntityNotFoundException(string message, Exception innerException) + : base(message, innerException) + { } + + /// + /// 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 EntityNotFoundException(SerializationInfo info, StreamingContext context) + : base(info, context) { - _msg = msg; + Id = info.GetValue(nameof(Id), typeof(object)); } - public override string Message + /// + /// 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) { - get { return _msg; } + if (info == null) + { + throw new ArgumentNullException(nameof(info)); + } + + info.AddValue(nameof(Id), Id); + + base.GetObjectData(info, context); } + /// + /// Returns a that represents this instance. + /// + /// + /// A that represents this instance. + /// public override string ToString() { var result = base.ToString(); diff --git a/src/Umbraco.Core/Persistence/FaultHandling/RetryLimitExceededException.cs b/src/Umbraco.Core/Persistence/FaultHandling/RetryLimitExceededException.cs index c537281dc9..abf8af35f5 100644 --- a/src/Umbraco.Core/Persistence/FaultHandling/RetryLimitExceededException.cs +++ b/src/Umbraco.Core/Persistence/FaultHandling/RetryLimitExceededException.cs @@ -4,59 +4,51 @@ using System.Runtime.Serialization; namespace Umbraco.Core.Persistence.FaultHandling { /// - /// The special type of exception that provides managed exit from a retry loop. The user code can use this - /// exception to notify the retry policy that no further retry attempts are required. + /// The special type of exception that provides managed exit from a retry loop. The user code can use this exception to notify the retry policy that no further retry attempts are required. /// + /// [Serializable] public sealed class RetryLimitExceededException : Exception { /// - /// Initializes a new instance of the class with a default error message. + /// Initializes a new instance of the class with a default error message. /// public RetryLimitExceededException() : this("RetryLimitExceeded") - { - } + { } /// - /// Initializes a new instance of the class with a specified error message. + /// Initializes a new instance of the class with a specified error message. /// /// The message that describes the error. public RetryLimitExceededException(string message) : base(message) - { - } + { } /// - /// Initializes a new instance of the class with a reference to the inner exception - /// that is the cause of this exception. + /// Initializes a new instance of the class with a reference to the inner exception that is the cause of this exception. /// /// The exception that is the cause of the current exception. public RetryLimitExceededException(Exception innerException) : base(innerException != null ? innerException.Message : "RetryLimitExceeded", innerException) - { - } + { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The message that describes the error. /// The exception that is the cause of the current exception. public RetryLimitExceededException(string message, Exception innerException) : base(message, innerException) - { - } + { } /// - /// Initializes a new instance of the class. + /// 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. - /// The parameter is null. - /// The class name is null or is zero (0). + /// The that holds the serialized object data about the exception being thrown. + /// The that contains contextual information about the source or destination. private RetryLimitExceededException(SerializationInfo info, StreamingContext context) : base(info, context) - { - } + { } } } diff --git a/src/Umbraco.Web/Install/InstallException.cs b/src/Umbraco.Web/Install/InstallException.cs index a9f254e921..44f6e4fe50 100644 --- a/src/Umbraco.Web/Install/InstallException.cs +++ b/src/Umbraco.Web/Install/InstallException.cs @@ -1,44 +1,105 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Runtime.Serialization; namespace Umbraco.Web.Install { /// - /// Used for steps to be able to return a json structure back to the UI + /// Used for steps to be able to return a JSON structure back to the UI. /// + /// + [Serializable] internal class InstallException : Exception { - private readonly string _message; + /// + /// Gets the view. + /// + /// + /// The view. + /// public string View { get; private set; } + + /// + /// Gets the view model. + /// + /// + /// The view model. + /// public object ViewModel { get; private set; } - public override string Message - { - get { return _message; } - } + /// + /// Initializes a new instance of the class. + /// + public InstallException() + { } + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. + public InstallException(string message) + : this(message, "error", null) + { } + + /// + /// Initializes a new instance of the class. + /// + /// The message. + /// The view model. + public InstallException(string message, object viewModel) + : this(message, "error", viewModel) + { } + + /// + /// Initializes a new instance of the class. + /// + /// The message. + /// The view. + /// The view model. public InstallException(string message, string view, object viewModel) + : base(message) { - _message = message; View = view; ViewModel = viewModel; } - public InstallException(string message, object viewModel) + /// + /// Initializes a new instance of the class. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, or a null reference ( in Visual Basic) if no inner exception is specified. + public InstallException(string message, Exception innerException) + : base(message, innerException) + { } + + /// + /// 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) { - _message = message; - View = "error"; - ViewModel = viewModel; + View = info.GetString(nameof(View)); + ViewModel = info.GetValue(nameof(ViewModel), typeof(object)); } - public InstallException(string message) + /// + /// 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) { - _message = message; - View = "error"; - ViewModel = null; + if (info == null) + { + throw new ArgumentNullException(nameof(info)); + } + + info.AddValue(nameof(View), View); + info.AddValue(nameof(ViewModel), ViewModel, typeof(object)); + + base.GetObjectData(info, context); } } } diff --git a/src/Umbraco.Web/Media/Exif/ExifExceptions.cs b/src/Umbraco.Web/Media/Exif/ExifExceptions.cs index 040e84ff99..136d1d9104 100644 --- a/src/Umbraco.Web/Media/Exif/ExifExceptions.cs +++ b/src/Umbraco.Web/Media/Exif/ExifExceptions.cs @@ -1,42 +1,87 @@ using System; +using System.Runtime.Serialization; namespace Umbraco.Web.Media.Exif { /// - /// The exception that is thrown when the format of the JPEG/Exif file - /// could not be understood. + /// The exception that is thrown when the format of the JPEG/EXIF file could not be understood. /// + /// + [Serializable] internal class NotValidExifFileException : Exception { + /// + /// Initializes a new instance of the class. + /// public NotValidExifFileException() - : base("Not a valid JPEG/Exif file.") - { - ; - } + : base("Not a valid JPEG/EXIF file.") + { } + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. public NotValidExifFileException(string message) : base(message) - { - ; - } + { } + + /// + /// Initializes a new instance of the class. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, or a null reference ( in Visual Basic) if no inner exception is specified. + public NotValidExifFileException(string message, Exception innerException) + : base(message, innerException) + { } + + /// + /// 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 NotValidExifFileException(SerializationInfo info, StreamingContext context) + : base(info, context) + { } } /// - /// The exception that is thrown when an invalid enum type is given to an - /// ExifEnumProperty. + /// The exception that is thrown when an invalid enum type is given to an ExifEnumProperty. /// + /// + [Serializable] internal class UnknownEnumTypeException : Exception { + /// + /// Initializes a new instance of the class. + /// public UnknownEnumTypeException() : base("Unknown enum type.") - { - ; - } + { } + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. public UnknownEnumTypeException(string message) : base(message) - { - ; - } + { } + + /// + /// Initializes a new instance of the class. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, or a null reference ( in Visual Basic) if no inner exception is specified. + public UnknownEnumTypeException(string message, Exception innerException) + : base(message, innerException) + { } + + /// + /// 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 UnknownEnumTypeException(SerializationInfo info, StreamingContext context) + : base(info, context) + { } } } diff --git a/src/Umbraco.Web/Media/Exif/JPEGExceptions.cs b/src/Umbraco.Web/Media/Exif/JPEGExceptions.cs index 631c3cb1b9..b18084e0be 100644 --- a/src/Umbraco.Web/Media/Exif/JPEGExceptions.cs +++ b/src/Umbraco.Web/Media/Exif/JPEGExceptions.cs @@ -1,99 +1,211 @@ using System; +using System.Runtime.Serialization; namespace Umbraco.Web.Media.Exif { /// - /// The exception that is thrown when the format of the image file - /// could not be understood. + /// The exception that is thrown when the format of the image file could not be understood. /// + /// + [Serializable] internal class NotValidImageFileException : Exception { + /// + /// Initializes a new instance of the class. + /// public NotValidImageFileException() : base("Not a valid image file.") - { - ; - } + { } + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. public NotValidImageFileException(string message) : base(message) - { - ; - } + { } + + /// + /// Initializes a new instance of the class. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, or a null reference ( in Visual Basic) if no inner exception is specified. + public NotValidImageFileException(string message, Exception innerException) + : base(message, innerException) + { } + + /// + /// 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 NotValidImageFileException(SerializationInfo info, StreamingContext context) + : base(info, context) + { } } /// - /// The exception that is thrown when the format of the JPEG file - /// could not be understood. + /// The exception that is thrown when the format of the JPEG file could not be understood. /// + /// + [Serializable] internal class NotValidJPEGFileException : Exception { + /// + /// Initializes a new instance of the class. + /// public NotValidJPEGFileException() : base("Not a valid JPEG file.") - { - ; - } + { } + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. public NotValidJPEGFileException(string message) : base(message) - { - ; - } + { } + + /// + /// Initializes a new instance of the class. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, or a null reference ( in Visual Basic) if no inner exception is specified. + public NotValidJPEGFileException(string message, Exception innerException) + : base(message, innerException) + { } + + /// + /// 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 NotValidJPEGFileException(SerializationInfo info, StreamingContext context) + : base(info, context) + { } } /// - /// The exception that is thrown when the format of the TIFF file - /// could not be understood. + /// The exception that is thrown when the format of the TIFF file could not be understood. /// + /// + [Serializable] internal class NotValidTIFFileException : Exception { + /// + /// Initializes a new instance of the class. + /// public NotValidTIFFileException() : base("Not a valid TIFF file.") - { - ; - } + { } + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. public NotValidTIFFileException(string message) : base(message) - { - ; - } + { } + + /// + /// Initializes a new instance of the class. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, or a null reference ( in Visual Basic) if no inner exception is specified. + public NotValidTIFFileException(string message, Exception innerException) + : base(message, innerException) + { } + + /// + /// 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 NotValidTIFFileException(SerializationInfo info, StreamingContext context) + : base(info, context) + { } } /// - /// The exception that is thrown when the format of the TIFF header - /// could not be understood. + /// The exception that is thrown when the format of the TIFF header could not be understood. /// + /// + [Serializable] internal class NotValidTIFFHeader : Exception { + /// + /// Initializes a new instance of the class. + /// public NotValidTIFFHeader() : base("Not a valid TIFF header.") - { - ; - } + { } + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. public NotValidTIFFHeader(string message) : base(message) - { - ; - } + { } + + /// + /// Initializes a new instance of the class. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, or a null reference ( in Visual Basic) if no inner exception is specified. + public NotValidTIFFHeader(string message, Exception innerException) + : base(message, innerException) + { } + + /// + /// 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 NotValidTIFFHeader(SerializationInfo info, StreamingContext context) + : base(info, context) + { } } /// /// The exception that is thrown when the length of a section exceeds 64 kB. /// + /// + [Serializable] internal class SectionExceeds64KBException : Exception { + /// + /// Initializes a new instance of the class. + /// public SectionExceeds64KBException() : base("Section length exceeds 64 kB.") - { - ; - } + { } + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. public SectionExceeds64KBException(string message) : base(message) - { - ; - } + { } + + /// + /// Initializes a new instance of the class. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, or a null reference ( in Visual Basic) if no inner exception is specified. + public SectionExceeds64KBException(string message, Exception innerException) + : base(message, innerException) + { } + + /// + /// 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 SectionExceeds64KBException(SerializationInfo info, StreamingContext context) + : base(info, context) + { } } } diff --git a/src/Umbraco.Web/Mvc/HttpUmbracoFormRouteStringException.cs b/src/Umbraco.Web/Mvc/HttpUmbracoFormRouteStringException.cs index b08fde081a..db2040665c 100644 --- a/src/Umbraco.Web/Mvc/HttpUmbracoFormRouteStringException.cs +++ b/src/Umbraco.Web/Mvc/HttpUmbracoFormRouteStringException.cs @@ -1,5 +1,4 @@ using System; -using System.Net; using System.Runtime.Serialization; using System.Web; @@ -12,6 +11,13 @@ namespace Umbraco.Web.Mvc [Serializable] public sealed class HttpUmbracoFormRouteStringException : HttpException { + /// + /// Initializes a new instance of the class. + /// + public HttpUmbracoFormRouteStringException() + { } + + /// /// Initializes a new instance of the class. /// /// The that holds the serialized object data about the exception being thrown. @@ -36,6 +42,5 @@ namespace Umbraco.Web.Mvc public HttpUmbracoFormRouteStringException(string message, Exception innerException) : base(message, innerException) { } - } } diff --git a/src/Umbraco.Web/Mvc/ModelBindingException.cs b/src/Umbraco.Web/Mvc/ModelBindingException.cs index d675ae4a65..548b548d4e 100644 --- a/src/Umbraco.Web/Mvc/ModelBindingException.cs +++ b/src/Umbraco.Web/Mvc/ModelBindingException.cs @@ -1,14 +1,45 @@ using System; +using System.Runtime.Serialization; namespace Umbraco.Web.Mvc { + /// + /// The exception that is thrown when an error occurs while binding a source to a model. + /// + /// + [Serializable] public class ModelBindingException : Exception { + /// + /// Initializes a new instance of the class. + /// public ModelBindingException() { } + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. public ModelBindingException(string message) : base(message) { } + + /// + /// Initializes a new instance of the class. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, or a null reference ( in Visual Basic) if no inner exception is specified. + public ModelBindingException(string message, Exception innerException) + : base(message, innerException) + { } + + /// + /// 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 ModelBindingException(SerializationInfo info, StreamingContext context) + : base(info, context) + { } } }