diff --git a/src/System.Private.CoreLib/shared/Internal/Resources/PRIExceptionInfo.cs b/src/System.Private.CoreLib/shared/Internal/Resources/PRIExceptionInfo.cs index 6593c27b1ad0..1ae4674a9813 100644 --- a/src/System.Private.CoreLib/shared/Internal/Resources/PRIExceptionInfo.cs +++ b/src/System.Private.CoreLib/shared/Internal/Resources/PRIExceptionInfo.cs @@ -2,13 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; - +#nullable enable namespace Internal.Resources { public class PRIExceptionInfo { - public string PackageSimpleName; - public string ResWFile; + public string? PackageSimpleName; + public string? ResWFile; } } diff --git a/src/System.Private.CoreLib/shared/System/Collections/Generic/KeyNotFoundException.cs b/src/System.Private.CoreLib/shared/System/Collections/Generic/KeyNotFoundException.cs index 3990e13784b9..75f3e91c0739 100644 --- a/src/System.Private.CoreLib/shared/System/Collections/Generic/KeyNotFoundException.cs +++ b/src/System.Private.CoreLib/shared/System/Collections/Generic/KeyNotFoundException.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; +#nullable enable using System.Runtime.Serialization; namespace System.Collections.Generic @@ -17,13 +17,13 @@ public KeyNotFoundException() HResult = HResults.COR_E_KEYNOTFOUND; } - public KeyNotFoundException(string message) + public KeyNotFoundException(string? message) : base(message) { HResult = HResults.COR_E_KEYNOTFOUND; } - public KeyNotFoundException(string message, Exception innerException) + public KeyNotFoundException(string? message, Exception? innerException) : base(message, innerException) { HResult = HResults.COR_E_KEYNOTFOUND; diff --git a/src/System.Private.CoreLib/shared/System/Diagnostics/Contracts/ContractException.cs b/src/System.Private.CoreLib/shared/System/Diagnostics/Contracts/ContractException.cs index 6a29ac339e33..9feaa2381275 100644 --- a/src/System.Private.CoreLib/shared/System/Diagnostics/Contracts/ContractException.cs +++ b/src/System.Private.CoreLib/shared/System/Diagnostics/Contracts/ContractException.cs @@ -2,11 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; -using System.Reflection; +#nullable enable using System.Runtime.Serialization; namespace System.Diagnostics.Contracts @@ -17,13 +13,13 @@ namespace System.Diagnostics.Contracts public sealed class ContractException : Exception { private readonly ContractFailureKind _kind; - private readonly string _userMessage; - private readonly string _condition; + private readonly string? _userMessage; + private readonly string? _condition; - public ContractFailureKind Kind { get { return _kind; } } - public string Failure { get { return this.Message; } } - public string UserMessage { get { return _userMessage; } } - public string Condition { get { return _condition; } } + public ContractFailureKind Kind => _kind; + public string Failure => this.Message; + public string? UserMessage => _userMessage; + public string? Condition => _condition; // Called by COM Interop, if we see COR_E_CODECONTRACTFAILED as an HRESULT. private ContractException() @@ -31,7 +27,7 @@ private ContractException() HResult = HResults.COR_E_CODECONTRACTFAILED; } - public ContractException(ContractFailureKind kind, string failure, string userMessage, string condition, Exception innerException) + public ContractException(ContractFailureKind kind, string? failure, string? userMessage, string? condition, Exception? innerException) : base(failure, innerException) { HResult = HResults.COR_E_CODECONTRACTFAILED; diff --git a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSourceException.cs b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSourceException.cs index be1bf3940a9e..2e821ac10da4 100644 --- a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSourceException.cs +++ b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSourceException.cs @@ -2,8 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Resources; +#nullable enable using System.Runtime.Serialization; #if ES_BUILD_STANDALONE @@ -33,13 +32,13 @@ public EventSourceException() : /// /// Initializes a new instance of the EventSourceException class with a specified error message. /// - public EventSourceException(string message) : base(message) { } + public EventSourceException(string? message) : base(message) { } /// /// Initializes a new instance of the EventSourceException class with a specified error message /// and a reference to the inner exception that is the cause of this exception. /// - public EventSourceException(string message, Exception innerException) : base(message, innerException) { } + public EventSourceException(string? message, Exception? innerException) : base(message, innerException) { } #if !ES_BUILD_PCL /// @@ -48,7 +47,7 @@ public EventSourceException(string message, Exception innerException) : base(mes protected EventSourceException(SerializationInfo info, StreamingContext context) : base(info, context) { } #endif - internal EventSourceException(Exception innerException) : + internal EventSourceException(Exception? innerException) : base(SR.EventSource_ListenerWriteFailure, innerException) { } } } diff --git a/src/System.Private.CoreLib/shared/System/IO/DirectoryNotFoundException.cs b/src/System.Private.CoreLib/shared/System/IO/DirectoryNotFoundException.cs index d7c6eacb9a96..58d4ee1a3f03 100644 --- a/src/System.Private.CoreLib/shared/System/IO/DirectoryNotFoundException.cs +++ b/src/System.Private.CoreLib/shared/System/IO/DirectoryNotFoundException.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Runtime.Serialization; namespace System.IO @@ -22,13 +23,13 @@ public DirectoryNotFoundException() HResult = HResults.COR_E_DIRECTORYNOTFOUND; } - public DirectoryNotFoundException(string message) + public DirectoryNotFoundException(string? message) : base(message) { HResult = HResults.COR_E_DIRECTORYNOTFOUND; } - public DirectoryNotFoundException(string message, Exception innerException) + public DirectoryNotFoundException(string? message, Exception? innerException) : base(message, innerException) { HResult = HResults.COR_E_DIRECTORYNOTFOUND; diff --git a/src/System.Private.CoreLib/shared/System/IO/EndOfStreamException.cs b/src/System.Private.CoreLib/shared/System/IO/EndOfStreamException.cs index 606073ad9ab0..69759aac1b4e 100644 --- a/src/System.Private.CoreLib/shared/System/IO/EndOfStreamException.cs +++ b/src/System.Private.CoreLib/shared/System/IO/EndOfStreamException.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Runtime.Serialization; namespace System.IO @@ -16,13 +17,13 @@ public EndOfStreamException() HResult = HResults.COR_E_ENDOFSTREAM; } - public EndOfStreamException(string message) + public EndOfStreamException(string? message) : base(message) { HResult = HResults.COR_E_ENDOFSTREAM; } - public EndOfStreamException(string message, Exception innerException) + public EndOfStreamException(string? message, Exception? innerException) : base(message, innerException) { HResult = HResults.COR_E_ENDOFSTREAM; diff --git a/src/System.Private.CoreLib/shared/System/IO/FileLoadException.cs b/src/System.Private.CoreLib/shared/System/IO/FileLoadException.cs index 8c31244e1db5..a893aca47b46 100644 --- a/src/System.Private.CoreLib/shared/System/IO/FileLoadException.cs +++ b/src/System.Private.CoreLib/shared/System/IO/FileLoadException.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Runtime.Serialization; namespace System.IO @@ -16,25 +17,25 @@ public FileLoadException() HResult = HResults.COR_E_FILELOAD; } - public FileLoadException(string message) + public FileLoadException(string? message) : base(message) { HResult = HResults.COR_E_FILELOAD; } - public FileLoadException(string message, Exception inner) + public FileLoadException(string? message, Exception? inner) : base(message, inner) { HResult = HResults.COR_E_FILELOAD; } - public FileLoadException(string message, string fileName) : base(message) + public FileLoadException(string? message, string? fileName) : base(message) { HResult = HResults.COR_E_FILELOAD; FileName = fileName; } - public FileLoadException(string message, string fileName, Exception inner) + public FileLoadException(string? message, string? fileName, Exception? inner) : base(message, inner) { HResult = HResults.COR_E_FILELOAD; @@ -53,8 +54,8 @@ public override string Message } } - public string FileName { get; } - public string FusionLog { get; } + public string? FileName { get; } + public string? FusionLog { get; } public override string ToString() { diff --git a/src/System.Private.CoreLib/shared/System/IO/FileNotFoundException.cs b/src/System.Private.CoreLib/shared/System/IO/FileNotFoundException.cs index 72cff4cfc0cd..9ab3eb38e534 100644 --- a/src/System.Private.CoreLib/shared/System/IO/FileNotFoundException.cs +++ b/src/System.Private.CoreLib/shared/System/IO/FileNotFoundException.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable +using System.Diagnostics; using System.Runtime.Serialization; namespace System.IO @@ -17,26 +19,26 @@ public FileNotFoundException() HResult = HResults.COR_E_FILENOTFOUND; } - public FileNotFoundException(string message) + public FileNotFoundException(string? message) : base(message) { HResult = HResults.COR_E_FILENOTFOUND; } - public FileNotFoundException(string message, Exception innerException) + public FileNotFoundException(string? message, Exception? innerException) : base(message, innerException) { HResult = HResults.COR_E_FILENOTFOUND; } - public FileNotFoundException(string message, string fileName) + public FileNotFoundException(string? message, string? fileName) : base(message) { HResult = HResults.COR_E_FILENOTFOUND; FileName = fileName; } - public FileNotFoundException(string message, string fileName, Exception innerException) + public FileNotFoundException(string? message, string? fileName, Exception? innerException) : base(message, innerException) { HResult = HResults.COR_E_FILENOTFOUND; @@ -48,6 +50,7 @@ public override string Message get { SetMessageField(); + Debug.Assert(_message != null, "_message was null after calling SetMessageField"); return _message; } } @@ -65,8 +68,8 @@ private void SetMessageField() } } - public string FileName { get; } - public string FusionLog { get; } + public string? FileName { get; } + public string? FusionLog { get; } public override string ToString() { diff --git a/src/System.Private.CoreLib/shared/System/IO/IOException.cs b/src/System.Private.CoreLib/shared/System/IO/IOException.cs index 04e653206137..ba8525f043c1 100644 --- a/src/System.Private.CoreLib/shared/System/IO/IOException.cs +++ b/src/System.Private.CoreLib/shared/System/IO/IOException.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; +#nullable enable using System.Runtime.Serialization; namespace System.IO @@ -17,19 +17,19 @@ public IOException() HResult = HResults.COR_E_IO; } - public IOException(string message) + public IOException(string? message) : base(message) { HResult = HResults.COR_E_IO; } - public IOException(string message, int hresult) + public IOException(string? message, int hresult) : base(message) { HResult = hresult; } - public IOException(string message, Exception innerException) + public IOException(string? message, Exception? innerException) : base(message, innerException) { HResult = HResults.COR_E_IO; diff --git a/src/System.Private.CoreLib/shared/System/IO/PathTooLongException.cs b/src/System.Private.CoreLib/shared/System/IO/PathTooLongException.cs index 7af2452736cb..e0a35f7c9ee1 100644 --- a/src/System.Private.CoreLib/shared/System/IO/PathTooLongException.cs +++ b/src/System.Private.CoreLib/shared/System/IO/PathTooLongException.cs @@ -2,8 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. - -using System; +#nullable enable using System.Runtime.Serialization; namespace System.IO @@ -18,13 +17,13 @@ public PathTooLongException() HResult = HResults.COR_E_PATHTOOLONG; } - public PathTooLongException(string message) + public PathTooLongException(string? message) : base(message) { HResult = HResults.COR_E_PATHTOOLONG; } - public PathTooLongException(string message, Exception innerException) + public PathTooLongException(string? message, Exception? innerException) : base(message, innerException) { HResult = HResults.COR_E_PATHTOOLONG; diff --git a/src/System.Private.CoreLib/shared/System/Reflection/AmbiguousMatchException.cs b/src/System.Private.CoreLib/shared/System/Reflection/AmbiguousMatchException.cs index 643a127c4983..aa321e99f185 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/AmbiguousMatchException.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/AmbiguousMatchException.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Runtime.Serialization; namespace System.Reflection @@ -16,13 +17,13 @@ public AmbiguousMatchException() HResult = HResults.COR_E_AMBIGUOUSMATCH; } - public AmbiguousMatchException(string message) + public AmbiguousMatchException(string? message) : base(message) { HResult = HResults.COR_E_AMBIGUOUSMATCH; } - public AmbiguousMatchException(string message, Exception inner) + public AmbiguousMatchException(string? message, Exception? inner) : base(message, inner) { HResult = HResults.COR_E_AMBIGUOUSMATCH; diff --git a/src/System.Private.CoreLib/shared/System/Reflection/CustomAttributeFormatException.cs b/src/System.Private.CoreLib/shared/System/Reflection/CustomAttributeFormatException.cs index 1d7d4a767185..0d38eaaebcc5 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/CustomAttributeFormatException.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/CustomAttributeFormatException.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Runtime.Serialization; namespace System.Reflection @@ -15,12 +16,12 @@ public CustomAttributeFormatException() { } - public CustomAttributeFormatException(string message) + public CustomAttributeFormatException(string? message) : this(message, null) { } - public CustomAttributeFormatException(string message, Exception inner) + public CustomAttributeFormatException(string? message, Exception? inner) : base(message, inner) { HResult = HResults.COR_E_CUSTOMATTRIBUTEFORMAT; diff --git a/src/System.Private.CoreLib/shared/System/Reflection/InvalidFilterCriteriaException.cs b/src/System.Private.CoreLib/shared/System/Reflection/InvalidFilterCriteriaException.cs index dedcc54f4cd3..e6e6468b1b8f 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/InvalidFilterCriteriaException.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/InvalidFilterCriteriaException.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Runtime.Serialization; namespace System.Reflection @@ -15,12 +16,12 @@ public InvalidFilterCriteriaException() { } - public InvalidFilterCriteriaException(string message) + public InvalidFilterCriteriaException(string? message) : this(message, null) { } - public InvalidFilterCriteriaException(string message, Exception inner) + public InvalidFilterCriteriaException(string? message, Exception? inner) : base(message, inner) { HResult = HResults.COR_E_INVALIDFILTERCRITERIA; diff --git a/src/System.Private.CoreLib/shared/System/Reflection/ReflectionTypeLoadException.cs b/src/System.Private.CoreLib/shared/System/Reflection/ReflectionTypeLoadException.cs index 5011c50053c9..ff2d85a83a89 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/ReflectionTypeLoadException.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/ReflectionTypeLoadException.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Runtime.Serialization; using System.Text; @@ -11,7 +12,7 @@ namespace System.Reflection [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public sealed class ReflectionTypeLoadException : SystemException, ISerializable { - public ReflectionTypeLoadException(Type[] classes, Exception[] exceptions) + public ReflectionTypeLoadException(Type[]? classes, Exception?[]? exceptions) : base(null) { Types = classes; @@ -19,7 +20,7 @@ public ReflectionTypeLoadException(Type[] classes, Exception[] exceptions) HResult = HResults.COR_E_REFLECTIONTYPELOAD; } - public ReflectionTypeLoadException(Type[] classes, Exception[] exceptions, string message) + public ReflectionTypeLoadException(Type[]? classes, Exception?[]? exceptions, string? message) : base(message) { Types = classes; @@ -40,9 +41,9 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont info.AddValue("Exceptions", LoaderExceptions, typeof(Exception[])); } - public Type[] Types { get; } + public Type[]? Types { get; } - public Exception[] LoaderExceptions { get; } + public Exception?[]? LoaderExceptions { get; } public override string Message => CreateString(isMessage: true); @@ -52,14 +53,14 @@ private string CreateString(bool isMessage) { string baseValue = isMessage ? base.Message : base.ToString(); - Exception[] exceptions = LoaderExceptions; + Exception?[]? exceptions = LoaderExceptions; if (exceptions == null || exceptions.Length == 0) { return baseValue; } var text = new StringBuilder(baseValue); - foreach (Exception e in exceptions) + foreach (Exception? e in exceptions) { if (e != null) { diff --git a/src/System.Private.CoreLib/shared/System/Reflection/TargetException.cs b/src/System.Private.CoreLib/shared/System/Reflection/TargetException.cs index c200000738c4..7a1b90a5f1cd 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/TargetException.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/TargetException.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Runtime.Serialization; namespace System.Reflection @@ -15,12 +16,12 @@ public TargetException() { } - public TargetException(string message) + public TargetException(string? message) : this(message, null) { } - public TargetException(string message, Exception inner) + public TargetException(string? message, Exception? inner) : base(message, inner) { HResult = HResults.COR_E_TARGET; diff --git a/src/System.Private.CoreLib/shared/System/Reflection/TargetInvocationException.cs b/src/System.Private.CoreLib/shared/System/Reflection/TargetInvocationException.cs index 822ddfdfb2c1..61312f28eda7 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/TargetInvocationException.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/TargetInvocationException.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Runtime.Serialization; namespace System.Reflection @@ -10,13 +11,13 @@ namespace System.Reflection [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public sealed class TargetInvocationException : ApplicationException { - public TargetInvocationException(Exception inner) + public TargetInvocationException(Exception? inner) : base(SR.Arg_TargetInvocationException, inner) { HResult = HResults.COR_E_TARGETINVOCATION; } - public TargetInvocationException(string message, Exception inner) + public TargetInvocationException(string? message, Exception? inner) : base(message, inner) { HResult = HResults.COR_E_TARGETINVOCATION; diff --git a/src/System.Private.CoreLib/shared/System/Reflection/TargetParameterCountException.cs b/src/System.Private.CoreLib/shared/System/Reflection/TargetParameterCountException.cs index c68c46729032..72b667ed4690 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/TargetParameterCountException.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/TargetParameterCountException.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Runtime.Serialization; namespace System.Reflection @@ -16,13 +17,13 @@ public TargetParameterCountException() HResult = HResults.COR_E_TARGETPARAMCOUNT; } - public TargetParameterCountException(string message) + public TargetParameterCountException(string? message) : base(message) { HResult = HResults.COR_E_TARGETPARAMCOUNT; } - public TargetParameterCountException(string message, Exception inner) + public TargetParameterCountException(string? message, Exception? inner) : base(message, inner) { HResult = HResults.COR_E_TARGETPARAMCOUNT; diff --git a/src/System.Private.CoreLib/shared/System/Resources/MissingManifestResourceException.cs b/src/System.Private.CoreLib/shared/System/Resources/MissingManifestResourceException.cs index 20914ac7e125..6f1499124917 100644 --- a/src/System.Private.CoreLib/shared/System/Resources/MissingManifestResourceException.cs +++ b/src/System.Private.CoreLib/shared/System/Resources/MissingManifestResourceException.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; +#nullable enable using System.Runtime.Serialization; namespace System.Resources @@ -17,13 +17,13 @@ public MissingManifestResourceException() HResult = System.HResults.COR_E_MISSINGMANIFESTRESOURCE; } - public MissingManifestResourceException(string message) + public MissingManifestResourceException(string? message) : base(message) { HResult = System.HResults.COR_E_MISSINGMANIFESTRESOURCE; } - public MissingManifestResourceException(string message, Exception inner) + public MissingManifestResourceException(string? message, Exception? inner) : base(message, inner) { HResult = System.HResults.COR_E_MISSINGMANIFESTRESOURCE; diff --git a/src/System.Private.CoreLib/shared/System/Resources/MissingSatelliteAssemblyException.cs b/src/System.Private.CoreLib/shared/System/Resources/MissingSatelliteAssemblyException.cs index 0bbc62673456..a403379c36aa 100644 --- a/src/System.Private.CoreLib/shared/System/Resources/MissingSatelliteAssemblyException.cs +++ b/src/System.Private.CoreLib/shared/System/Resources/MissingSatelliteAssemblyException.cs @@ -15,7 +15,7 @@ ** ===========================================================*/ -using System; +#nullable enable using System.Runtime.Serialization; namespace System.Resources @@ -24,7 +24,7 @@ namespace System.Resources [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public class MissingSatelliteAssemblyException : SystemException { - private string _cultureName; + private string? _cultureName; public MissingSatelliteAssemblyException() : base(SR.MissingSatelliteAssembly_Default) @@ -32,20 +32,20 @@ public MissingSatelliteAssemblyException() HResult = System.HResults.COR_E_MISSINGSATELLITEASSEMBLY; } - public MissingSatelliteAssemblyException(string message) + public MissingSatelliteAssemblyException(string? message) : base(message) { HResult = System.HResults.COR_E_MISSINGSATELLITEASSEMBLY; } - public MissingSatelliteAssemblyException(string message, string cultureName) + public MissingSatelliteAssemblyException(string? message, string? cultureName) : base(message) { HResult = System.HResults.COR_E_MISSINGSATELLITEASSEMBLY; _cultureName = cultureName; } - public MissingSatelliteAssemblyException(string message, Exception inner) + public MissingSatelliteAssemblyException(string? message, Exception? inner) : base(message, inner) { HResult = System.HResults.COR_E_MISSINGSATELLITEASSEMBLY; @@ -56,9 +56,6 @@ protected MissingSatelliteAssemblyException(SerializationInfo info, StreamingCon { } - public string CultureName - { - get { return _cultureName; } - } + public string? CultureName => _cultureName; } } diff --git a/src/System.Private.CoreLib/shared/System/Runtime/AmbiguousImplementationException.cs b/src/System.Private.CoreLib/shared/System/Runtime/AmbiguousImplementationException.cs index 9e43ec0196a3..401a8fcb0e38 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/AmbiguousImplementationException.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/AmbiguousImplementationException.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Globalization; +#nullable enable using System.Runtime.Serialization; namespace System.Runtime @@ -17,13 +17,13 @@ public AmbiguousImplementationException() HResult = HResults.COR_E_AMBIGUOUSIMPLEMENTATION; } - public AmbiguousImplementationException(string message) + public AmbiguousImplementationException(string? message) : base(message) { HResult = HResults.COR_E_AMBIGUOUSIMPLEMENTATION; } - public AmbiguousImplementationException(string message, Exception innerException) + public AmbiguousImplementationException(string? message, Exception? innerException) : base(message, innerException) { HResult = HResults.COR_E_AMBIGUOUSIMPLEMENTATION; diff --git a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeWrappedException.cs b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeWrappedException.cs index 72996c6dfc8d..6af2b280b3a1 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeWrappedException.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeWrappedException.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Runtime.Serialization; namespace System.Runtime.CompilerServices diff --git a/src/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs b/src/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs index 3578d43d9cfa..57cbcf78c6f1 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Diagnostics; namespace System.Runtime.ExceptionServices diff --git a/src/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionNotification.cs b/src/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionNotification.cs index 605588d657f8..9357e2fa5aa3 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionNotification.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionNotification.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable namespace System.Runtime.ExceptionServices { // Definition of the argument-type passed to the FirstChanceException event handler diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/COMException.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/COMException.cs index 0823c5670c15..cc51358add34 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/COMException.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/COMException.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Runtime.Serialization; using System.Globalization; using System.Text; @@ -23,19 +24,19 @@ public COMException() HResult = HResults.E_FAIL; } - public COMException(string message) + public COMException(string? message) : base(message) { HResult = HResults.E_FAIL; } - public COMException(string message, Exception inner) + public COMException(string? message, Exception? inner) : base(message, inner) { HResult = HResults.E_FAIL; } - public COMException(string message, int errorCode) + public COMException(string? message, int errorCode) : base(message) { HResult = errorCode; @@ -58,13 +59,13 @@ public override string ToString() s.Append(": ").Append(message); } - Exception innerException = InnerException; + Exception? innerException = InnerException; if (innerException != null) { s.Append(" ---> ").Append(innerException.ToString()); } - string stackTrace = StackTrace; + string? stackTrace = StackTrace; if (stackTrace != null) s.Append(Environment.NewLine).Append(stackTrace); diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ExternalException.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ExternalException.cs index ab5a84c08ab5..0ac83759ded2 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ExternalException.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ExternalException.cs @@ -12,7 +12,7 @@ ** =============================================================================*/ -using System; +#nullable enable using System.Globalization; using System.Runtime.Serialization; @@ -30,19 +30,19 @@ public ExternalException() HResult = HResults.E_FAIL; } - public ExternalException(string message) + public ExternalException(string? message) : base(message) { HResult = HResults.E_FAIL; } - public ExternalException(string message, Exception inner) + public ExternalException(string? message, Exception? inner) : base(message, inner) { HResult = HResults.E_FAIL; } - public ExternalException(string message, int errorCode) + public ExternalException(string? message, int errorCode) : base(message) { HResult = errorCode; @@ -68,13 +68,12 @@ public override string ToString() string s = className + " (0x" + HResult.ToString("X8", CultureInfo.InvariantCulture) + ")"; - if (!(string.IsNullOrEmpty(message))) + if (!string.IsNullOrEmpty(message)) { s = s + ": " + message; } - Exception innerException = InnerException; - + Exception? innerException = InnerException; if (innerException != null) { s = s + " ---> " + innerException.ToString(); diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidComObjectException.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidComObjectException.cs index 3b00be1318a9..c2820f48ce97 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidComObjectException.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidComObjectException.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Runtime.Serialization; namespace System.Runtime.InteropServices @@ -21,13 +22,13 @@ public InvalidComObjectException() HResult = HResults.COR_E_INVALIDCOMOBJECT; } - public InvalidComObjectException(string message) + public InvalidComObjectException(string? message) : base(message) { HResult = HResults.COR_E_INVALIDCOMOBJECT; } - public InvalidComObjectException(string message, Exception inner) + public InvalidComObjectException(string? message, Exception? inner) : base(message, inner) { HResult = HResults.COR_E_INVALIDCOMOBJECT; diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidOleVariantTypeException.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidOleVariantTypeException.cs index 48b1ac3b049e..cde7b5d218e0 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidOleVariantTypeException.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidOleVariantTypeException.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Runtime.Serialization; namespace System.Runtime.InteropServices @@ -20,13 +21,13 @@ public InvalidOleVariantTypeException() HResult = HResults.COR_E_INVALIDOLEVARIANTTYPE; } - public InvalidOleVariantTypeException(string message) + public InvalidOleVariantTypeException(string? message) : base(message) { HResult = HResults.COR_E_INVALIDOLEVARIANTTYPE; } - public InvalidOleVariantTypeException(string message, Exception inner) + public InvalidOleVariantTypeException(string? message, Exception? inner) : base(message, inner) { HResult = HResults.COR_E_INVALIDOLEVARIANTTYPE; diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/MarshalDirectiveException.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/MarshalDirectiveException.cs index 3bb1140f5e91..b827ee334436 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/MarshalDirectiveException.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/MarshalDirectiveException.cs @@ -11,8 +11,7 @@ ** =============================================================================*/ - -using System; +#nullable enable using System.Runtime.Serialization; namespace System.Runtime.InteropServices @@ -27,13 +26,13 @@ public MarshalDirectiveException() HResult = HResults.COR_E_MARSHALDIRECTIVE; } - public MarshalDirectiveException(string message) + public MarshalDirectiveException(string? message) : base(message) { HResult = HResults.COR_E_MARSHALDIRECTIVE; } - public MarshalDirectiveException(string message, Exception inner) + public MarshalDirectiveException(string? message, Exception? inner) : base(message, inner) { HResult = HResults.COR_E_MARSHALDIRECTIVE; diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/SEHException.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/SEHException.cs index 85e900b3cad5..dd7b615db23b 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/SEHException.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/SEHException.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Runtime.Serialization; namespace System.Runtime.InteropServices @@ -19,13 +20,13 @@ public SEHException() HResult = HResults.E_FAIL; } - public SEHException(string message) + public SEHException(string? message) : base(message) { HResult = HResults.E_FAIL; } - public SEHException(string message, Exception inner) + public SEHException(string? message, Exception? inner) : base(message, inner) { HResult = HResults.E_FAIL; diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayRankMismatchException.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayRankMismatchException.cs index 5df2ed484ce7..98e4dcb2bf4e 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayRankMismatchException.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayRankMismatchException.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Runtime.Serialization; namespace System.Runtime.InteropServices @@ -20,13 +21,13 @@ public SafeArrayRankMismatchException() HResult = HResults.COR_E_SAFEARRAYRANKMISMATCH; } - public SafeArrayRankMismatchException(string message) + public SafeArrayRankMismatchException(string? message) : base(message) { HResult = HResults.COR_E_SAFEARRAYRANKMISMATCH; } - public SafeArrayRankMismatchException(string message, Exception inner) + public SafeArrayRankMismatchException(string? message, Exception? inner) : base(message, inner) { HResult = HResults.COR_E_SAFEARRAYRANKMISMATCH; diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayTypeMismatchException.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayTypeMismatchException.cs index d1e787c4f87a..58bb3f87bbf1 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayTypeMismatchException.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayTypeMismatchException.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Runtime.Serialization; namespace System.Runtime.InteropServices @@ -20,13 +21,13 @@ public SafeArrayTypeMismatchException() HResult = HResults.COR_E_SAFEARRAYTYPEMISMATCH; } - public SafeArrayTypeMismatchException(string message) + public SafeArrayTypeMismatchException(string? message) : base(message) { HResult = HResults.COR_E_SAFEARRAYTYPEMISMATCH; } - public SafeArrayTypeMismatchException(string message, Exception inner) + public SafeArrayTypeMismatchException(string? message, Exception? inner) : base(message, inner) { HResult = HResults.COR_E_SAFEARRAYTYPEMISMATCH; diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Serialization/DeserializationBlockedException.cs b/src/System.Private.CoreLib/shared/System/Runtime/Serialization/DeserializationBlockedException.cs index 8c8f7809fbcf..82deb7d61414 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/Serialization/DeserializationBlockedException.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/Serialization/DeserializationBlockedException.cs @@ -2,8 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; - +#nullable enable namespace System.Runtime.Serialization { // Thrown when a dangerous action would be performed during deserialization @@ -21,13 +20,13 @@ public DeserializationBlockedException() // Creates a new DeserializationBlockedException with a message indicating an opt-out switch // for a particular part of SerializationGuard - public DeserializationBlockedException(string message) + public DeserializationBlockedException(string? message) : base(message) { HResult = HResults.COR_E_SERIALIZATION; } - public DeserializationBlockedException(Exception innerException) + public DeserializationBlockedException(Exception? innerException) : base(SR.Serialization_DangerousDeserialization, innerException) { HResult = HResults.COR_E_SERIALIZATION; diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationException.cs b/src/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationException.cs index 172e6c5cd534..922a11e6ba08 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationException.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationException.cs @@ -2,29 +2,30 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Runtime.Serialization; - +#nullable enable namespace System.Runtime.Serialization { [Serializable] [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public class SerializationException : SystemException { - // Creates a new SerializationException with its message - // string set to a default message. + /// + /// Creates a new SerializationException with its message + /// string set to a default message. + /// public SerializationException() : base(SR.SerializationException) { HResult = HResults.COR_E_SERIALIZATION; } - public SerializationException(string message) + public SerializationException(string? message) : base(message) { HResult = HResults.COR_E_SERIALIZATION; } - public SerializationException(string message, Exception innerException) + public SerializationException(string? message, Exception? innerException) : base(message, innerException) { HResult = HResults.COR_E_SERIALIZATION; diff --git a/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/WindowsRuntime/ExceptionSupport.cs b/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/WindowsRuntime/ExceptionSupport.cs index 1772105d1e13..8d133a5f059a 100644 --- a/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/WindowsRuntime/ExceptionSupport.cs +++ b/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/WindowsRuntime/ExceptionSupport.cs @@ -1,8 +1,9 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. + +#nullable enable using System; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices.WindowsRuntime; namespace Internal.Runtime.InteropServices.WindowsRuntime @@ -13,7 +14,7 @@ public static class ExceptionSupport /// Attach restricted error information to the exception if it may apply to that exception, returning /// back the input value /// - public static Exception AttachRestrictedErrorInfo(Exception e) + public static Exception? AttachRestrictedErrorInfo(Exception? e) { // If there is no exception, then the restricted error info doesn't apply to it if (e != null) @@ -71,7 +72,7 @@ public static Exception AttachRestrictedErrorInfo(Exception e) /// for the application to be invoked to process the error. /// /// true if the error was reported, false if not (ie running on Win8) - public static bool ReportUnhandledError(Exception ex) + public static bool ReportUnhandledError(Exception? ex) { return WindowsRuntimeMarshal.ReportUnhandledError(ex); } diff --git a/src/System.Private.CoreLib/src/System/IO/FileLoadException.CoreCLR.cs b/src/System.Private.CoreLib/src/System/IO/FileLoadException.CoreCLR.cs index ef593b974d6a..9da8e35f29db 100644 --- a/src/System.Private.CoreLib/src/System/IO/FileLoadException.CoreCLR.cs +++ b/src/System.Private.CoreLib/src/System/IO/FileLoadException.CoreCLR.cs @@ -2,17 +2,16 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Globalization; -using System.Runtime.InteropServices; +#nullable enable using System.Runtime.CompilerServices; -using System.Security; +using System.Runtime.InteropServices; namespace System.IO { public partial class FileLoadException { // Do not delete: this is invoked from native code. - private FileLoadException(string fileName, string fusionLog, int hResult) + private FileLoadException(string? fileName, string? fusionLog, int hResult) : base(null) { HResult = hResult; @@ -21,12 +20,12 @@ private FileLoadException(string fileName, string fusionLog, int hResult) _message = FormatFileLoadExceptionMessage(FileName, HResult); } - internal static string FormatFileLoadExceptionMessage(string fileName, int hResult) + internal static string FormatFileLoadExceptionMessage(string? fileName, int hResult) { - string format = null; + string? format = null; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761 GetStringHandleOnStack needs to be attributed GetFileLoadExceptionMessage(hResult, JitHelpers.GetStringHandleOnStack(ref format)); - string message = null; + string? message = null; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761 GetStringHandleOnStack needs to be attributed if (hResult == System.HResults.COR_E_BADEXEFORMAT) message = SR.Arg_BadImageFormatException; else diff --git a/src/System.Private.CoreLib/src/System/IO/FileNotFoundException.CoreCLR.cs b/src/System.Private.CoreLib/src/System/IO/FileNotFoundException.CoreCLR.cs index 99645f0f2ded..c20b0d798aef 100644 --- a/src/System.Private.CoreLib/src/System/IO/FileNotFoundException.CoreCLR.cs +++ b/src/System.Private.CoreLib/src/System/IO/FileNotFoundException.CoreCLR.cs @@ -2,12 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable namespace System.IO { public partial class FileNotFoundException { // Do not delete: this is invoked from native code. - private FileNotFoundException(string fileName, string fusionLog, int hResult) + private FileNotFoundException(string? fileName, string? fusionLog, int hResult) : base(null) { HResult = hResult; @@ -17,4 +18,3 @@ private FileNotFoundException(string fileName, string fusionLog, int hResult) } } } -