diff --git a/src/Umbraco.Core/DatabaseContext.cs b/src/Umbraco.Core/DatabaseContext.cs
index 687e9b6af3..9a1061ebef 100644
--- a/src/Umbraco.Core/DatabaseContext.cs
+++ b/src/Umbraco.Core/DatabaseContext.cs
@@ -10,6 +10,7 @@ using NPoco;
using Semver;
using Umbraco.Core.Configuration;
using Umbraco.Core.DI;
+using Umbraco.Core.Exceptions;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence;
@@ -270,8 +271,8 @@ namespace Umbraco.Core
/// A logger.
private static void SaveConnectionString(string connectionString, string providerName, ILogger logger)
{
- if (string.IsNullOrWhiteSpace(connectionString)) throw new ArgumentException("Value cannot be null nor empty.", nameof(connectionString));
- if (string.IsNullOrWhiteSpace(providerName)) throw new ArgumentException("Value cannot be null nor empty.", nameof(providerName));
+ if (string.IsNullOrWhiteSpace(connectionString)) throw new ArgumentNullOrEmptyException(nameof(connectionString));
+ if (string.IsNullOrWhiteSpace(providerName)) throw new ArgumentNullOrEmptyException(nameof(providerName));
// set the connection string for the new datalayer
var connectionStringSettings = new ConnectionStringSettings(GlobalSettings.UmbracoConnectionName, connectionString, providerName);
diff --git a/src/Umbraco.Core/Exceptions/ArgumentNullOrEmptyException.cs b/src/Umbraco.Core/Exceptions/ArgumentNullOrEmptyException.cs
new file mode 100644
index 0000000000..90cc20c404
--- /dev/null
+++ b/src/Umbraco.Core/Exceptions/ArgumentNullOrEmptyException.cs
@@ -0,0 +1,30 @@
+using System;
+
+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.
+ ///
+ public class ArgumentNullOrEmptyException : ArgumentNullException
+ {
+ ///
+ /// 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)
+ : base(paramName)
+ { }
+
+ ///
+ /// 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)
+ { }
+ }
+}
diff --git a/src/Umbraco.Core/IO/PhysicalFileSystem.cs b/src/Umbraco.Core/IO/PhysicalFileSystem.cs
index 29a0a84dac..107ce71957 100644
--- a/src/Umbraco.Core/IO/PhysicalFileSystem.cs
+++ b/src/Umbraco.Core/IO/PhysicalFileSystem.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using Umbraco.Core.DI;
+using Umbraco.Core.Exceptions;
using Umbraco.Core.Logging;
namespace Umbraco.Core.IO
@@ -34,14 +35,9 @@ namespace Umbraco.Core.IO
public PhysicalFileSystem(string rootPath, string rootUrl)
{
- if (string.IsNullOrEmpty(rootPath))
- throw new ArgumentException("The argument 'rootPath' cannot be null or empty.");
-
- if (string.IsNullOrEmpty(rootUrl))
- throw new ArgumentException("The argument 'rootUrl' cannot be null or empty.");
-
- if (rootPath.StartsWith("~/"))
- throw new ArgumentException("The rootPath argument cannot be a virtual path and cannot start with '~/'");
+ if (string.IsNullOrEmpty(rootPath)) throw new ArgumentNullOrEmptyException(nameof(rootPath));
+ if (string.IsNullOrEmpty(rootUrl)) throw new ArgumentNullOrEmptyException(nameof(rootUrl));
+ if (rootPath.StartsWith("~/")) throw new ArgumentException("The rootPath argument cannot be a virtual path and cannot start with '~/'");
// rootPath should be... rooted, as in, it's a root path!
// but the test suite App.config cannot really "root" anything so we'll have to do it here
diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentModelAttribute.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentModelAttribute.cs
index a1712bf160..7e94636935 100644
--- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentModelAttribute.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentModelAttribute.cs
@@ -1,4 +1,5 @@
using System;
+using Umbraco.Core.Exceptions;
namespace Umbraco.Core.Models.PublishedContent
{
@@ -16,8 +17,7 @@ namespace Umbraco.Core.Models.PublishedContent
/// The content type alias.
public PublishedContentModelAttribute(string contentTypeAlias)
{
- if (string.IsNullOrWhiteSpace(contentTypeAlias))
- throw new ArgumentException("Argument cannot be null nor empty.", "contentTypeAlias");
+ if (string.IsNullOrWhiteSpace(contentTypeAlias)) throw new ArgumentNullOrEmptyException(nameof(contentTypeAlias));
ContentTypeAlias = contentTypeAlias;
}
diff --git a/src/Umbraco.Core/Persistence/DefaultDatabaseFactory.cs b/src/Umbraco.Core/Persistence/DefaultDatabaseFactory.cs
index 79bd5931b3..db469957a9 100644
--- a/src/Umbraco.Core/Persistence/DefaultDatabaseFactory.cs
+++ b/src/Umbraco.Core/Persistence/DefaultDatabaseFactory.cs
@@ -7,6 +7,7 @@ using System.Threading;
using NPoco;
using NPoco.FluentMappings;
using Umbraco.Core.Configuration;
+using Umbraco.Core.Exceptions;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.FaultHandling;
using Umbraco.Core.Persistence.Mappers;
@@ -73,7 +74,7 @@ namespace Umbraco.Core.Persistence
if (sqlSyntaxProviders == null) throw new ArgumentNullException(nameof(sqlSyntaxProviders));
if (logger == null) throw new ArgumentNullException(nameof(logger));
if (umbracoDatabaseAccessor == null) throw new ArgumentNullException(nameof(umbracoDatabaseAccessor));
- if (string.IsNullOrWhiteSpace(connectionStringName)) throw new ArgumentException("Value cannot be null nor empty.", nameof(connectionStringName));
+ if (string.IsNullOrWhiteSpace(connectionStringName)) throw new ArgumentNullOrEmptyException(nameof(connectionStringName));
if (mappers == null) throw new ArgumentNullException(nameof(mappers));
_mappers = mappers;
diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj
index 0c0ff2997b..726fb76b6e 100644
--- a/src/Umbraco.Core/Umbraco.Core.csproj
+++ b/src/Umbraco.Core/Umbraco.Core.csproj
@@ -273,6 +273,7 @@
+
diff --git a/src/Umbraco.Core/Xml/XmlHelper.cs b/src/Umbraco.Core/Xml/XmlHelper.cs
index c4227b6276..17fe6fa526 100644
--- a/src/Umbraco.Core/Xml/XmlHelper.cs
+++ b/src/Umbraco.Core/Xml/XmlHelper.cs
@@ -6,6 +6,7 @@ using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
+using Umbraco.Core.Exceptions;
using Umbraco.Core.IO;
namespace Umbraco.Core.Xml
@@ -26,7 +27,7 @@ namespace Umbraco.Core.Xml
{
if (xml == null) throw new ArgumentNullException("xml");
if (n == null) throw new ArgumentNullException("n");
- if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value cannot be null or whitespace.", "name");
+ if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
if (n.Attributes == null)
{
@@ -376,7 +377,7 @@ namespace Umbraco.Core.Xml
public static XmlAttribute AddAttribute(XmlDocument xd, string name, string value)
{
if (xd == null) throw new ArgumentNullException("xd");
- if (string.IsNullOrEmpty(name)) throw new ArgumentException("Value cannot be null or empty.", "name");
+ if (string.IsNullOrEmpty(name)) throw new ArgumentNullOrEmptyException(nameof(name));
var temp = xd.CreateAttribute(name);
temp.Value = value;
@@ -393,7 +394,7 @@ namespace Umbraco.Core.Xml
public static XmlNode AddTextNode(XmlDocument xd, string name, string value)
{
if (xd == null) throw new ArgumentNullException("xd");
- if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value cannot be null or whitespace.", "name");
+ if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
var temp = xd.CreateNode(XmlNodeType.Element, name, "");
temp.AppendChild(xd.CreateTextNode(value));
@@ -412,7 +413,7 @@ namespace Umbraco.Core.Xml
{
if (xd == null) throw new ArgumentNullException("xd");
if (parent == null) throw new ArgumentNullException("parent");
- if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value cannot be null or whitespace.", "name");
+ if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
var child = parent.SelectSingleNode(name);
if (child != null)
@@ -433,7 +434,7 @@ namespace Umbraco.Core.Xml
public static XmlNode AddCDataNode(XmlDocument xd, string name, string value)
{
if (xd == null) throw new ArgumentNullException("xd");
- if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value cannot be null or whitespace.", "name");
+ if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
var temp = xd.CreateNode(XmlNodeType.Element, name, "");
temp.AppendChild(xd.CreateCDataSection(value));
@@ -452,7 +453,7 @@ namespace Umbraco.Core.Xml
{
if (xd == null) throw new ArgumentNullException("xd");
if (parent == null) throw new ArgumentNullException("parent");
- if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value cannot be null or whitespace.", "name");
+ if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
var child = parent.SelectSingleNode(name);
if (child != null)