Nullable: Runtime serialization, COM, Vector, remaining IO, and other (#23895)
authorStephen Toub <stoub@microsoft.com>
Fri, 12 Apr 2019 14:08:38 +0000 (10:08 -0400)
committerGitHub <noreply@github.com>
Fri, 12 Apr 2019 14:08:38 +0000 (10:08 -0400)
67 files changed:
src/System.Private.CoreLib/shared/Internal/Padding.cs
src/System.Private.CoreLib/shared/Internal/Resources/WindowsRuntimeResourceManagerBase.cs
src/System.Private.CoreLib/shared/Internal/Threading/Tasks/AsyncCausalitySupport.cs
src/System.Private.CoreLib/shared/Interop/Unix/Interop.Errors.cs
src/System.Private.CoreLib/shared/Interop/Unix/Interop.IOErrors.cs
src/System.Private.CoreLib/shared/Interop/Unix/Interop.Libraries.cs
src/System.Private.CoreLib/shared/System/Collections/Generic/IEnumerable.cs
src/System.Private.CoreLib/shared/System/Collections/IEnumerable.cs
src/System.Private.CoreLib/shared/System/Environment.Unix.cs
src/System.Private.CoreLib/shared/System/Exception.cs
src/System.Private.CoreLib/shared/System/Globalization/CultureInfo.Windows.cs
src/System.Private.CoreLib/shared/System/Globalization/CultureNotFoundException.cs
src/System.Private.CoreLib/shared/System/IO/BinaryReader.cs
src/System.Private.CoreLib/shared/System/IO/BinaryWriter.cs
src/System.Private.CoreLib/shared/System/IO/StreamReader.cs
src/System.Private.CoreLib/shared/System/IO/StreamWriter.cs
src/System.Private.CoreLib/shared/System/IO/TextWriter.cs
src/System.Private.CoreLib/shared/System/MissingMemberException.cs
src/System.Private.CoreLib/shared/System/Numerics/BitOperations.cs
src/System.Private.CoreLib/shared/System/Numerics/ConstantHelper.cs
src/System.Private.CoreLib/shared/System/Numerics/ConstantHelper.tt
src/System.Private.CoreLib/shared/System/Numerics/Register.cs
src/System.Private.CoreLib/shared/System/Numerics/Register.tt
src/System.Private.CoreLib/shared/System/Numerics/Vector.cs
src/System.Private.CoreLib/shared/System/Numerics/Vector.tt
src/System.Private.CoreLib/shared/System/Reflection/ReflectionTypeLoadException.cs
src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeWrappedException.cs
src/System.Private.CoreLib/shared/System/Runtime/ConstrainedExecution/CriticalFinalizerObject.cs
src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IBindCtx.cs
src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IConnectionPoint.cs
src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IConnectionPointContainer.cs
src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumConnectionPoints.cs
src/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs
src/System.Private.CoreLib/shared/System/Runtime/MemoryFailPoint.Unix.cs
src/System.Private.CoreLib/shared/System/Runtime/MemoryFailPoint.Windows.cs
src/System.Private.CoreLib/shared/System/Runtime/MemoryFailPoint.cs
src/System.Private.CoreLib/shared/System/Runtime/Serialization/DeserializationToken.cs
src/System.Private.CoreLib/shared/System/Runtime/Serialization/DeserializationTracker.cs
src/System.Private.CoreLib/shared/System/Runtime/Serialization/IDeserializationCallback.cs
src/System.Private.CoreLib/shared/System/Runtime/Serialization/IFormatterConverter.cs
src/System.Private.CoreLib/shared/System/Runtime/Serialization/IObjectReference.cs
src/System.Private.CoreLib/shared/System/Runtime/Serialization/ISafeSerializationData.cs
src/System.Private.CoreLib/shared/System/Runtime/Serialization/ISerializable.cs
src/System.Private.CoreLib/shared/System/Runtime/Serialization/SafeSerializationEventArgs.cs
src/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationInfo.cs
src/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationInfoEnumerator.cs
src/System.Private.CoreLib/shared/System/Runtime/Serialization/StreamingContext.cs
src/System.Private.CoreLib/shared/System/Security/SecurityException.cs
src/System.Private.CoreLib/shared/System/StringComparer.cs
src/System.Private.CoreLib/shared/System/TimeZoneInfo.AdjustmentRule.cs
src/System.Private.CoreLib/shared/System/TimeZoneInfo.Unix.cs
src/System.Private.CoreLib/shared/System/TimeZoneInfo.cs
src/System.Private.CoreLib/shared/System/UnitySerializationHolder.cs
src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/InMemoryAssemblyLoader.cs
src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/IsolatedComponentLoadContext.cs
src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/WindowsRuntime/ActivationFactoryLoader.cs
src/System.Private.CoreLib/src/Interop/Unix/Interop.Libraries.cs
src/System.Private.CoreLib/src/System/Exception.CoreCLR.cs
src/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Unix.cs
src/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Windows.cs
src/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs
src/System.Private.CoreLib/src/System/Reflection/Metadata/AssemblyExtensions.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/ComDataHelpers.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/EnumerableToDispatchMarshaler.cs
src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs
src/System.Private.CoreLib/src/System/WeakReference.cs
src/System.Private.CoreLib/src/System/WeakReferenceOfT.cs

index 14bf998..86050b7 100644 (file)
@@ -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.InteropServices;
 
 namespace Internal
index 6594ae6..531b0fd 100644 (file)
@@ -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.Globalization;
 
 namespace Internal.Resources
@@ -11,11 +11,11 @@ namespace Internal.Resources
     // allowing us to ask for a WinRT-specific ResourceManager.
     public abstract class WindowsRuntimeResourceManagerBase
     {
-        public abstract bool Initialize(string libpath, string reswFilename, out PRIExceptionInfo exceptionInfo);
+        public abstract bool Initialize(string libpath, string reswFilename, out PRIExceptionInfo? exceptionInfo);
 
-        public abstract string GetString(string stringName, string startingCulture, string neutralResourcesCulture);
+        public abstract string GetString(string stringName, string? startingCulture, string? neutralResourcesCulture);
 
-        public abstract CultureInfo GlobalResourceContextBestFitCultureInfo
+        public abstract CultureInfo? GlobalResourceContextBestFitCultureInfo
         {
             get;
         }
@@ -26,7 +26,7 @@ namespace Internal.Resources
         /// Check whether CultureData exists for specified cultureName
         /// This API is used for WindowsRuntimeResourceManager in System.Runtime.WindowsRuntime
         /// </summary>
-        public static bool IsValidCulture(string cultureName)
+        public static bool IsValidCulture(string? cultureName)
         {
             return CultureData.GetCultureData(cultureName, /* useUserOverride */ true) != null;
         }
index dcea41d..54df96d 100644 (file)
@@ -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.Threading.Tasks;
 using System.Runtime.CompilerServices;
 
index 554d065..5d9ccab 100644 (file)
@@ -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;
 using System.Runtime.InteropServices;
 
@@ -179,7 +180,7 @@ internal static partial class Interop
                 message = buffer;
             }
 
-            return Marshal.PtrToStringAnsi((IntPtr)message);
+            return Marshal.PtrToStringAnsi((IntPtr)message)!;
         }
 
         [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ConvertErrorPlatformToPal")]
index b3f9a3f..666220e 100644 (file)
@@ -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;
 using System.Diagnostics;
 using System.IO;
@@ -10,7 +11,7 @@ using Microsoft.Win32.SafeHandles;
 
 internal static partial class Interop
 {
-    private static void ThrowExceptionForIoErrno(ErrorInfo errorInfo, string path, bool isDirectory, Func<ErrorInfo, ErrorInfo> errorRewriter)
+    private static void ThrowExceptionForIoErrno(ErrorInfo errorInfo, string? path, bool isDirectory, Func<ErrorInfo, ErrorInfo>? errorRewriter)
     {
         Debug.Assert(errorInfo.Error != Error.SUCCESS);
         Debug.Assert(errorInfo.Error != Error.EINTR, "EINTR errors should be handled by the native shim and never bubble up to managed code");
@@ -23,7 +24,7 @@ internal static partial class Interop
         throw Interop.GetExceptionForIoErrno(errorInfo, path, isDirectory);
     }
 
-    internal static void CheckIo(Error error, string path = null, bool isDirectory = false, Func<ErrorInfo, ErrorInfo> errorRewriter = null)
+    internal static void CheckIo(Error error, string? path = null, bool isDirectory = false, Func<ErrorInfo, ErrorInfo>? errorRewriter = null)
     {
         if (error != Interop.Error.SUCCESS)
         {
@@ -43,7 +44,7 @@ internal static partial class Interop
     /// <returns>
     /// On success, returns the non-negative result long that was validated.
     /// </returns>
-    internal static long CheckIo(long result, string path = null, bool isDirectory = false, Func<ErrorInfo, ErrorInfo> errorRewriter = null)
+    internal static long CheckIo(long result, string? path = null, bool isDirectory = false, Func<ErrorInfo, ErrorInfo>? errorRewriter = null)
     {
         if (result < 0)
         {
@@ -61,7 +62,7 @@ internal static partial class Interop
     /// <returns>
     /// On success, returns the non-negative result int that was validated.
     /// </returns>
-    internal static int CheckIo(int result, string path = null, bool isDirectory = false, Func<ErrorInfo, ErrorInfo> errorRewriter = null)
+    internal static int CheckIo(int result, string? path = null, bool isDirectory = false, Func<ErrorInfo, ErrorInfo>? errorRewriter = null)
     {
         CheckIo((long)result, path, isDirectory, errorRewriter);
 
@@ -76,7 +77,7 @@ internal static partial class Interop
     /// <returns>
     /// On success, returns the non-negative result IntPtr that was validated.
     /// </returns>
-    internal static IntPtr CheckIo(IntPtr result, string path = null, bool isDirectory = false, Func<ErrorInfo, ErrorInfo> errorRewriter = null)
+    internal static IntPtr CheckIo(IntPtr result, string? path = null, bool isDirectory = false, Func<ErrorInfo, ErrorInfo>? errorRewriter = null)
     {
         CheckIo((long)result, path, isDirectory, errorRewriter);
 
@@ -91,7 +92,7 @@ internal static partial class Interop
     /// <returns>
     /// On success, returns the valid SafeFileHandle that was validated.
     /// </returns>
-    internal static TSafeHandle CheckIo<TSafeHandle>(TSafeHandle handle, string path = null, bool isDirectory = false, Func<ErrorInfo, ErrorInfo> errorRewriter = null)
+    internal static TSafeHandle CheckIo<TSafeHandle>(TSafeHandle handle, string? path = null, bool isDirectory = false, Func<ErrorInfo, ErrorInfo>? errorRewriter = null)
         where TSafeHandle : SafeHandle
     {
         if (handle.IsInvalid)
@@ -109,7 +110,7 @@ internal static partial class Interop
     /// <param name="path">The path with which this error is associated.  This may be null.</param>
     /// <param name="isDirectory">true if the <paramref name="path"/> is known to be a directory; otherwise, false.</param>
     /// <returns></returns>
-    internal static Exception GetExceptionForIoErrno(ErrorInfo errorInfo, string path = null, bool isDirectory = false)
+    internal static Exception GetExceptionForIoErrno(ErrorInfo errorInfo, string? path = null, bool isDirectory = false)
     {
         // Translate the errno into a known set of exception types.  For cases where multiple errnos map
         // to the same exception type, include an inner exception with the details.
index 02d0092..6c620bf 100644 (file)
@@ -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
 internal static partial class Interop
 {
     internal static partial class Libraries
index 46d30cb..d3ef9e8 100644 (file)
@@ -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;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-
+#nullable enable
 namespace System.Collections.Generic
 {
     // Implement this interface if you need to support foreach semantics.
index f2c91f5..5ca523f 100644 (file)
@@ -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.InteropServices;
 
 namespace System.Collections
index e5a630b..d74086b 100644 (file)
@@ -216,7 +216,7 @@ namespace System
                 {
                     using (var reader = new StreamReader(userDirsPath))
                     {
-                        string line;
+                        string? line;
                         while ((line = reader.ReadLine()) != null)
                         {
                             // Example lines:
index c2522d5..0fc37ee 100644 (file)
@@ -41,8 +41,8 @@ namespace System
                 throw new ArgumentNullException(nameof(info));
 
             _message = info.GetString("Message"); // Do not rename (binary serialization)
-            _data = (IDictionary)(info.GetValueNoThrow("Data", typeof(IDictionary))); // Do not rename (binary serialization)
-            _innerException = (Exception)(info.GetValue("InnerException", typeof(Exception))); // Do not rename (binary serialization)
+            _data = (IDictionary?)(info.GetValueNoThrow("Data", typeof(IDictionary))); // Do not rename (binary serialization)
+            _innerException = (Exception?)(info.GetValue("InnerException", typeof(Exception))); // Do not rename (binary serialization)
             _helpURL = info.GetString("HelpURL"); // Do not rename (binary serialization)
             _stackTraceString = info.GetString("StackTraceString"); // Do not rename (binary serialization)
             _HResult = info.GetInt32("HResult"); // Do not rename (binary serialization)
index 09041e9..8d312df 100644 (file)
@@ -82,7 +82,7 @@ namespace System.Globalization
                 return null;
             }
 
-            CultureInfo toReturn;
+            CultureInfo? toReturn;
 
             try
             {
index cb61d50..87d26f8 100644 (file)
@@ -62,7 +62,7 @@ namespace System.Globalization
             : base(info, context)
         {
             _invalidCultureId = (int?)info.GetValue("InvalidCultureId", typeof(int?));
-            _invalidCultureName = (string)info.GetValue("InvalidCultureName", typeof(string));
+            _invalidCultureName = (string?)info.GetValue("InvalidCultureName", typeof(string));
         }
 
         public override void GetObjectData(SerializationInfo info, StreamingContext context)
index 273d4c7..280afe6 100644 (file)
@@ -14,6 +14,7 @@
 **
 ============================================================*/
 
+#nullable enable
 using System.Buffers.Binary;
 using System.Diagnostics;
 using System.Runtime.CompilerServices;
@@ -29,8 +30,8 @@ namespace System.IO
         private readonly Stream _stream;
         private readonly byte[] _buffer;
         private readonly Decoder _decoder;
-        private byte[] _charBytes;
-        private char[] _charBuffer;
+        private byte[]? _charBytes;
+        private char[]? _charBuffer;
         private int _maxCharsSize;  // From MaxCharBytesSize & Encoding
 
         // Performance optimization for Read() w/ Unicode.  Speeds us up by ~40% 
@@ -305,7 +306,7 @@ namespace System.IO
                 _charBuffer = new char[_maxCharsSize];
             }
 
-            StringBuilder sb = null;
+            StringBuilder? sb = null;
             do
             {
                 readLength = ((stringLength - currPos) > MaxCharBytesSize) ? MaxCharBytesSize : (stringLength - currPos);
@@ -396,7 +397,7 @@ namespace System.IO
                 }
 
                 int position = 0;
-                byte[] byteBuffer = null;
+                byte[]? byteBuffer = null;
                 if (_isMemoryStream)
                 {
                     Debug.Assert(_stream is MemoryStream);
@@ -580,7 +581,7 @@ namespace System.IO
         // reasons. More about the subject in: https://github.com/dotnet/coreclr/pull/22102
         protected virtual void FillBuffer(int numBytes)
         {
-            if (_buffer != null && (numBytes < 0 || numBytes > _buffer.Length))
+            if (numBytes < 0 || numBytes > _buffer.Length)
             {
                 throw new ArgumentOutOfRangeException(nameof(numBytes), SR.ArgumentOutOfRange_BinaryReaderFillBuffer);
             }
index 9b6f865..89ebf98 100644 (file)
@@ -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.Text;
 using System.Diagnostics;
 using System.Buffers;
@@ -25,7 +26,7 @@ namespace System.IO
         private bool _leaveOpen;
 
         // Perf optimization stuff
-        private byte[] _largeByteBuffer;  // temp space for writing chars.
+        private byte[]? _largeByteBuffer;  // temp space for writing chars.
         private int _maxChars;   // max # of chars we can put in _largeByteBuffer
         // Size should be around the max number of chars/string * Encoding's max bytes/char
         private const int LargeByteBufferSize = 256;
index bc5c00f..9d836c0 100644 (file)
@@ -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;
 using System.Diagnostics.CodeAnalysis;
 using System.Text;
@@ -28,10 +29,10 @@ namespace System.IO
         private const int MinBufferSize = 128;
 
         private readonly Stream _stream;
-        private Encoding _encoding;
-        private Decoder _decoder;
-        private readonly byte[] _byteBuffer;
-        private char[] _charBuffer;
+        private Encoding _encoding = null!; // only null in NullStreamReader where this is never used
+        private Decoder _decoder = null!; // only null in NullStreamReader where this is never used
+        private readonly byte[] _byteBuffer = null!; // only null in NullStreamReader where this is never used
+        private char[] _charBuffer = null!; // only null in NullStreamReader where this is never used
         private int _charPos;
         private int _charLen;
         // Record the number of valid bytes in the byteBuffer, for a few checks.
@@ -94,6 +95,7 @@ namespace System.IO
 
         private StreamReader()
         {
+            Debug.Assert(this is NullStreamReader);
             _stream = Stream.Null;
             _closable = true;
         }
@@ -769,7 +771,7 @@ namespace System.IO
         // contain the terminating carriage return and/or line feed. The returned
         // value is null if the end of the input stream has been reached.
         //
-        public override string ReadLine()
+        public override string? ReadLine()
         {
             ThrowIfDisposed();
             CheckAsyncTaskInProgress();
@@ -782,7 +784,7 @@ namespace System.IO
                 }
             }
 
-            StringBuilder sb = null;
+            StringBuilder? sb = null;
             do
             {
                 int i = _charPos;
@@ -825,7 +827,7 @@ namespace System.IO
             return sb.ToString();
         }
 
-        public override Task<string> ReadLineAsync()
+        public override Task<string?> ReadLineAsync()
         {
             // If we have been inherited into a subclass, the following implementation could be incorrect
             // since it does not call through to Read() which a subclass might have overridden.  
@@ -839,20 +841,20 @@ namespace System.IO
             ThrowIfDisposed();
             CheckAsyncTaskInProgress();
 
-            Task<string> task = ReadLineAsyncInternal();
+            Task<string?> task = ReadLineAsyncInternal();
             _asyncReadTask = task;
 
             return task;
         }
 
-        private async Task<string> ReadLineAsyncInternal()
+        private async Task<string?> ReadLineAsyncInternal()
         {
             if (_charPos == _charLen && (await ReadBufferAsync().ConfigureAwait(false)) == 0)
             {
                 return null;
             }
 
-            StringBuilder sb = null;
+            StringBuilder? sb = null;
 
             do
             {
@@ -1342,7 +1344,7 @@ namespace System.IO
                 return 0;
             }
 
-            public override string ReadLine()
+            public override string? ReadLine()
             {
                 return null;
             }
index 8140d79..3a99919 100644 (file)
@@ -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;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
@@ -335,7 +336,7 @@ namespace System.IO
         }
 
         [MethodImpl(MethodImplOptions.NoInlining)] // prevent WriteSpan from bloating call sites
-        public override void Write(char[] buffer)
+        public override void Write(char[]? buffer)
         {
             WriteSpan(buffer, appendNewLine: false);
         }
@@ -453,13 +454,13 @@ namespace System.IO
         }
 
         [MethodImpl(MethodImplOptions.NoInlining)] // prevent WriteSpan from bloating call sites
-        public override void Write(string value)
+        public override void Write(string? value)
         {
             WriteSpan(value, appendNewLine: false);
         }
 
         [MethodImpl(MethodImplOptions.NoInlining)] // prevent WriteSpan from bloating call sites
-        public override void WriteLine(string value)
+        public override void WriteLine(string? value)
         {
             CheckAsyncTaskInProgress();
             WriteSpan(value, appendNewLine: true);
@@ -484,8 +485,8 @@ namespace System.IO
         private void WriteFormatHelper(string format, ParamsArray args, bool appendNewLine)
         {
             StringBuilder sb =
-                StringBuilderCache.Acquire(format.Length + args.Length * 8)
-                .AppendFormatHelper(null, format, args);
+                StringBuilderCache.Acquire((format?.Length ?? 0) + args.Length * 8)
+                .AppendFormatHelper(null, format!, args); // AppendFormatHelper will appropriately throw ArgumentNullException for a null format
 
             StringBuilder.ChunkEnumerator chunks = sb.GetChunks();
 
@@ -502,7 +503,7 @@ namespace System.IO
             StringBuilderCache.Release(sb);
         }
 
-        public override void Write(string format, object arg0)
+        public override void Write(string format, object? arg0)
         {
             if (GetType() == typeof(StreamWriter))
             {
@@ -514,7 +515,7 @@ namespace System.IO
             }
         }
 
-        public override void Write(string format, object arg0, object arg1)
+        public override void Write(string format, object? arg0, object? arg1)
         {
             if (GetType() == typeof(StreamWriter))
             {
@@ -526,7 +527,7 @@ namespace System.IO
             }
         }
 
-        public override void Write(string format, object arg0, object arg1, object arg2)
+        public override void Write(string format, object? arg0, object? arg1, object? arg2)
         {
             if (GetType() == typeof(StreamWriter))
             {
@@ -538,10 +539,14 @@ namespace System.IO
             }
         }
 
-        public override void Write(string format, params object[] arg)
+        public override void Write(string format, params object?[] arg)
         {
             if (GetType() == typeof(StreamWriter))
             {
+                if (arg == null)
+                {
+                    throw new ArgumentNullException((format == null) ? nameof(format) : nameof(arg)); // same as base logic
+                }
                 WriteFormatHelper(format, new ParamsArray(arg), appendNewLine: false);
             }
             else
@@ -550,7 +555,7 @@ namespace System.IO
             }
         }
 
-        public override void WriteLine(string format, object arg0)
+        public override void WriteLine(string format, object? arg0)
         {
             if (GetType() == typeof(StreamWriter))
             {
@@ -562,7 +567,7 @@ namespace System.IO
             }
         }
 
-        public override void WriteLine(string format, object arg0, object arg1)
+        public override void WriteLine(string format, object? arg0, object? arg1)
         {
             if (GetType() == typeof(StreamWriter))
             {
@@ -574,7 +579,7 @@ namespace System.IO
             }
         }
 
-        public override void WriteLine(string format, object arg0, object arg1, object arg2)
+        public override void WriteLine(string format, object? arg0, object? arg1, object? arg2)
         {
             if (GetType() == typeof(StreamWriter))
             {
@@ -586,10 +591,14 @@ namespace System.IO
             }
         }
 
-        public override void WriteLine(string format, params object[] arg)
+        public override void WriteLine(string format, params object?[] arg)
         {
             if (GetType() == typeof(StreamWriter))
             {
+                if (arg == null)
+                {
+                    throw new ArgumentNullException(nameof(arg));
+                }
                 WriteFormatHelper(format, new ParamsArray(arg), appendNewLine: true);
             }
             else
@@ -661,7 +670,7 @@ namespace System.IO
             _this.CharPos_Prop = charPos;
         }
 
-        public override Task WriteAsync(string value)
+        public override Task WriteAsync(string? value)
         {
             // If we have been inherited into a subclass, the following implementation could be incorrect
             // since it does not call through to Write() which a subclass might have overridden.  
@@ -901,7 +910,7 @@ namespace System.IO
         }
 
 
-        public override Task WriteLineAsync(string value)
+        public override Task WriteLineAsync(string? value)
         {
             if (value == null)
             {
index 4d555e5..f648df0 100644 (file)
@@ -146,7 +146,7 @@ namespace System.IO
         // Write(char) for each of the characters in the character array.
         // If the character array is null, nothing is written.
         //
-        public virtual void Write(char[] buffer)
+        public virtual void Write(char[]? buffer)
         {
             if (buffer != null)
             {
@@ -362,7 +362,7 @@ namespace System.IO
         // Writes an array of characters followed by a line terminator to the text
         // stream.
         //
-        public virtual void WriteLine(char[] buffer)
+        public virtual void WriteLine(char[]? buffer)
         {
             Write(buffer);
             WriteLine();
@@ -584,7 +584,7 @@ namespace System.IO
             }
         }
 
-        public Task WriteAsync(char[] buffer)
+        public Task WriteAsync(char[]? buffer)
         {
             if (buffer == null)
             {
@@ -659,7 +659,7 @@ namespace System.IO
             }
         }
 
-        public Task WriteLineAsync(char[] buffer)
+        public Task WriteLineAsync(char[]? buffer)
         {
             if (buffer == null)
             {
@@ -793,7 +793,7 @@ namespace System.IO
             public override void Write(char value) => _out.Write(value);
 
             [MethodImpl(MethodImplOptions.Synchronized)]
-            public override void Write(char[] buffer) => _out.Write(buffer);
+            public override void Write(char[]? buffer) => _out.Write(buffer);
 
             [MethodImpl(MethodImplOptions.Synchronized)]
             public override void Write(char[] buffer, int index, int count) => _out.Write(buffer, index, count);
@@ -856,7 +856,7 @@ namespace System.IO
             public override void WriteLine(decimal value) => _out.WriteLine(value);
 
             [MethodImpl(MethodImplOptions.Synchronized)]
-            public override void WriteLine(char[] buffer) => _out.WriteLine(buffer);
+            public override void WriteLine(char[]? buffer) => _out.WriteLine(buffer);
 
             [MethodImpl(MethodImplOptions.Synchronized)]
             public override void WriteLine(char[] buffer, int index, int count) => _out.WriteLine(buffer, index, count);
index e04a468..cc8be87 100644 (file)
@@ -40,7 +40,7 @@ namespace System
         {
             ClassName = info.GetString("MMClassName");
             MemberName = info.GetString("MMMemberName");
-            Signature = (byte[])info.GetValue("MMSignature", typeof(byte[]));
+            Signature = (byte[]?)info.GetValue("MMSignature", typeof(byte[]));
         }
 
         public override void GetObjectData(SerializationInfo info, StreamingContext context)
index 3813b9a..e2a6720 100644 (file)
@@ -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.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.Intrinsics.X86;
index 3fb3086..4426c88 100644 (file)
@@ -1,7 +1,8 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// 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.Runtime.CompilerServices;
 
 namespace System.Numerics
@@ -139,4 +140,4 @@ namespace System.Numerics
             return value;
         }
     }
-}
+}
\ No newline at end of file
index dd823ab..9d89754 100644 (file)
@@ -14,6 +14,7 @@
 <#@ import namespace="System.Runtime.InteropServices" #>
 <#@ include file="GenerationConfig.ttinclude" #><# GenerateCopyrightHeader(); #>
 
+#nullable enable
 using System.Runtime.CompilerServices;
 
 namespace System.Numerics
index 8efa85b..a5dfd5e 100644 (file)
@@ -1,7 +1,8 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// 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.Runtime.InteropServices;
 
 namespace System.Numerics
index 676b89f..f447051 100644 (file)
@@ -8,6 +8,7 @@
 <#@ import namespace="System.Diagnostics" #>
 <#@ include file="GenerationConfig.ttinclude" #><# GenerateCopyrightHeader(); #>
 
+#nullable enable
 using System.Runtime.InteropServices;
 
 namespace System.Numerics
@@ -43,4 +44,4 @@ namespace System.Numerics
     }
 #>        #endregion Internal Storage Fields
     }
-}
\ No newline at end of file
+}
index 0c1787d..3f7832a 100644 (file)
@@ -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
 #if netcoreapp
 using Internal.Runtime.CompilerServices;
 #endif
@@ -1195,7 +1196,7 @@ namespace System.Numerics
         /// <param name="obj">The Object to compare against.</param>
         /// <returns>True if the Object is equal to this vector; False otherwise.</returns>
         [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
-        public override bool Equals(object obj)
+        public override bool Equals(object? obj)
         {
             if (!(obj is Vector<T>))
             {
@@ -1562,7 +1563,7 @@ namespace System.Numerics
         /// </summary>
         /// <param name="format">The format of individual elements.</param>
         /// <returns>The string representation.</returns>
-        public string ToString(string format)
+        public string ToString(string? format)
         {
             return ToString(format, CultureInfo.CurrentCulture);
         }
@@ -1574,7 +1575,7 @@ namespace System.Numerics
         /// <param name="format">The format of individual elements.</param>
         /// <param name="formatProvider">The format provider to use when formatting elements.</param>
         /// <returns>The string representation.</returns>
-        public string ToString(string format, IFormatProvider formatProvider)
+        public string ToString(string? format, IFormatProvider? formatProvider)
         {
             StringBuilder sb = new StringBuilder();
             string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator;
index 4b0fc4f..5132b09 100644 (file)
@@ -7,6 +7,7 @@
 <#@ import namespace="System.Runtime.InteropServices" #>
 <#@ include file="GenerationConfig.ttinclude" #><# GenerateCopyrightHeader(); #>
 
+#nullable enable
 #if netcoreapp
 using Internal.Runtime.CompilerServices;
 #endif
@@ -450,7 +451,7 @@ namespace System.Numerics
         /// <param name="obj">The Object to compare against.</param>
         /// <returns>True if the Object is equal to this vector; False otherwise.</returns>
         [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
-        public override bool Equals(object obj)
+        public override bool Equals(object? obj)
         {
             if (!(obj is Vector<T>))
             {
@@ -591,7 +592,7 @@ namespace System.Numerics
         /// </summary>
         /// <param name="format">The format of individual elements.</param>
         /// <returns>The string representation.</returns>
-        public string ToString(string format)
+        public string ToString(string? format)
         {
             return ToString(format, CultureInfo.CurrentCulture);
         }
@@ -603,7 +604,7 @@ namespace System.Numerics
         /// <param name="format">The format of individual elements.</param>
         /// <param name="formatProvider">The format provider to use when formatting elements.</param>
         /// <returns>The string representation.</returns>
-        public string ToString(string format, IFormatProvider formatProvider)
+        public string ToString(string? format, IFormatProvider? formatProvider)
         {
             StringBuilder sb = new StringBuilder();
             string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator;
index ff2d85a..c471fd9 100644 (file)
@@ -31,7 +31,7 @@ namespace System.Reflection
         private ReflectionTypeLoadException(SerializationInfo info, StreamingContext context)
             : base(info, context)
         {
-            LoaderExceptions = (Exception[])(info.GetValue("Exceptions", typeof(Exception[])));
+            LoaderExceptions = (Exception[]?)(info.GetValue("Exceptions", typeof(Exception[])));
         }
 
         public override void GetObjectData(SerializationInfo info, StreamingContext context)
index 6af2b28..863de07 100644 (file)
@@ -28,7 +28,7 @@ namespace System.Runtime.CompilerServices
         private RuntimeWrappedException(SerializationInfo info, StreamingContext context)
             : base(info, context)
         {
-            _wrappedException = info.GetValue("WrappedException", typeof(object));
+            _wrappedException = info.GetValue("WrappedException", typeof(object))!;
         }
 
         public override void GetObjectData(SerializationInfo info, StreamingContext context)
index a535b94..f662c63 100644 (file)
@@ -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.InteropServices.ComTypes
 {
     [StructLayout(LayoutKind.Sequential)]
@@ -23,10 +24,10 @@ namespace System.Runtime.InteropServices.ComTypes
         void ReleaseBoundObjects();
         void SetBindOptions([In()] ref BIND_OPTS pbindopts);
         void GetBindOptions(ref BIND_OPTS pbindopts);
-        void GetRunningObjectTable(out IRunningObjectTable pprot);
+        void GetRunningObjectTable(out IRunningObjectTable? pprot);
         void RegisterObjectParam([MarshalAs(UnmanagedType.LPWStr)] string pszKey, [MarshalAs(UnmanagedType.Interface)] object punk);
-        void GetObjectParam([MarshalAs(UnmanagedType.LPWStr)] string pszKey, [MarshalAs(UnmanagedType.Interface)] out object ppunk);
-        void EnumObjectParam(out IEnumString ppenum);
+        void GetObjectParam([MarshalAs(UnmanagedType.LPWStr)] string pszKey, [MarshalAs(UnmanagedType.Interface)] out object? ppunk);
+        void EnumObjectParam(out IEnumString? ppenum);
         [PreserveSig]
         int RevokeObjectParam([MarshalAs(UnmanagedType.LPWStr)] string pszKey);
     }
index b2ce192..ab5cf2e 100644 (file)
@@ -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.InteropServices.ComTypes
 {
     [Guid("B196B286-BAB4-101A-B69C-00AA00341D07")]
index 84c590d..9203b67 100644 (file)
@@ -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.InteropServices.ComTypes
 {
     [Guid("B196B284-BAB4-101A-B69C-00AA00341D07")]
@@ -10,6 +11,6 @@ namespace System.Runtime.InteropServices.ComTypes
     public interface IConnectionPointContainer
     {
         void EnumConnectionPoints(out IEnumConnectionPoints ppEnum);
-        void FindConnectionPoint([In] ref Guid riid, out IConnectionPoint ppCP);
+        void FindConnectionPoint([In] ref Guid riid, out IConnectionPoint? ppCP);
     }
 }
index 99df6ac..8536c0f 100644 (file)
@@ -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.InteropServices.ComTypes
 {
     [Guid("B196B285-BAB4-101A-B69C-00AA00341D07")]
index 1ba1c6d..b9da126 100644 (file)
@@ -7,7 +7,6 @@ using System.Collections.Generic;
 using System.Diagnostics;
 using System.IO;
 using System.Reflection;
-using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Threading;
 
index 2f53052..37575d0 100644 (file)
@@ -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
 {
     public sealed partial class MemoryFailPoint
index 966c3a2..5ab51a7 100644 (file)
@@ -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.IO;
 using System.Runtime.InteropServices;
 
index 88e222f..4e4ed29 100644 (file)
@@ -13,7 +13,7 @@
 ** 
 ===========================================================*/
 
-using System.IO;
+#nullable enable
 using System.Threading;
 using System.Runtime.CompilerServices;
 using System.Runtime.ConstrainedExecution;
index e879ef5..92e0fcb 100644 (file)
@@ -2,18 +2,15 @@
 // 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.Runtime.CompilerServices;
-using System.Threading;
-
+#nullable enable
 namespace System.Runtime.Serialization
 {
     // Tracks whether deserialization is currently in progress
     public readonly struct DeserializationToken : IDisposable
     {
-        private readonly DeserializationTracker _tracker;
+        private readonly DeserializationTracker? _tracker;
 
-        internal DeserializationToken(DeserializationTracker tracker)
+        internal DeserializationToken(DeserializationTracker? tracker)
         {
             _tracker = tracker;
         }
index fb4ac51..04ea6bd 100644 (file)
@@ -2,9 +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.Runtime.CompilerServices;
-
+#nullable enable
 namespace System.Runtime.Serialization
 {
     // Tracks whether deserialization is currently in progress
index a1c1671..67628b4 100644 (file)
@@ -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.Serialization
 {
     public interface IDeserializationCallback
index c173144..d0e3d81 100644 (file)
@@ -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.Serialization
 {
     [CLSCompliant(false)]
@@ -23,6 +24,6 @@ namespace System.Runtime.Serialization
         double ToDouble(object value);
         decimal ToDecimal(object value);
         DateTime ToDateTime(object value);
-        string ToString(object value);
+        string? ToString(object value);
     }
 }
index d41bc50..f232cf5 100644 (file)
@@ -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.Serialization
 {
     public interface IObjectReference
index 5089d13..f4babe4 100644 (file)
@@ -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.Serialization
 {
     //
index 383b3f0..8edf628 100644 (file)
@@ -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.Serialization
 {
     public interface ISerializable
index 896b91f..1987042 100644 (file)
@@ -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.Collections.Generic;
 
 namespace System.Runtime.Serialization
index 44aadf3..2a4ab0e 100644 (file)
@@ -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.Collections;
+#nullable enable
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Security;
@@ -18,7 +18,7 @@ namespace System.Runtime.Serialization
         // Even though we have a dictionary, we're still keeping all the arrays around for back-compat. 
         // Otherwise we may run into potentially breaking behaviors like GetEnumerator() not returning entries in the same order they were added.
         private string[] _names;
-        private object[] _values;
+        private object?[] _values;
         private Type[] _types;
         private int _count;
         private Dictionary<string, int> _nameToIndex;
@@ -282,7 +282,7 @@ namespace System.Runtime.Serialization
             _types = newTypes;
         }
 
-        public void AddValue(string name, object value, Type type)
+        public void AddValue(string name, object? value, Type type)
         {
             if (null == name)
             {
@@ -297,7 +297,7 @@ namespace System.Runtime.Serialization
             AddValueInternal(name, value, type);
         }
 
-        public void AddValue(string name, object value)
+        public void AddValue(string name, object? value)
         {
             if (null == value)
             {
@@ -383,7 +383,7 @@ namespace System.Runtime.Serialization
             AddValue(name, (object)value, typeof(DateTime));
         }
 
-        internal void AddValueInternal(string name, object value, Type type)
+        internal void AddValueInternal(string name, object? value, Type type)
         {
             if (_nameToIndex.ContainsKey(name))
             {
@@ -462,7 +462,7 @@ namespace System.Runtime.Serialization
         /// <param name="name"> The name of the element to find.</param>
         /// <param name="foundType"> The type of the element associated with the given name.</param>
         /// <returns>The value of the element at the position associated with name.</returns>
-        private object GetElement(string name, out Type foundType)
+        private object? GetElement(string name, out Type foundType)
         {
             int index = FindElement(name);
             if (index == -1)
@@ -478,7 +478,7 @@ namespace System.Runtime.Serialization
             return _values[index];
         }
 
-        private object GetElementNoThrow(string name, out Type foundType)
+        private object? GetElementNoThrow(string name, out Type? foundType)
         {
             int index = FindElement(name);
             if (index == -1)
@@ -495,7 +495,7 @@ namespace System.Runtime.Serialization
             return _values[index];
         }
 
-        public object GetValue(string name, Type type)
+        public object? GetValue(string name, Type type)
         {
             if ((object)type == null)
             {
@@ -504,10 +504,9 @@ namespace System.Runtime.Serialization
 
             if (!type.IsRuntimeImplemented())
                 throw new ArgumentException(SR.Argument_MustBeRuntimeType);
-            Type foundType;
-            object value;
 
-            value = GetElement(name, out foundType);
+            Type foundType;
+            object? value = GetElement(name, out foundType);
 
             if (ReferenceEquals(foundType, type) || type.IsAssignableFrom(foundType) || value == null)
             {
@@ -518,15 +517,13 @@ namespace System.Runtime.Serialization
             return _converter.Convert(value, type);
         }
 
-        internal object GetValueNoThrow(string name, Type type)
+        internal object? GetValueNoThrow(string name, Type type)
         {
-            Type foundType;
-            object value;
-
             Debug.Assert((object)type != null, "[SerializationInfo.GetValue]type ==null");
             Debug.Assert(type.IsRuntimeImplemented(), "[SerializationInfo.GetValue]type is not a runtime type");
 
-            value = GetElementNoThrow(name, out foundType);
+            Type? foundType;
+            object? value = GetElementNoThrow(name, out foundType);
             if (value == null)
                 return null;
 
@@ -543,111 +540,111 @@ namespace System.Runtime.Serialization
         public bool GetBoolean(string name)
         {
             Type foundType;
-            object value = GetElement(name, out foundType);
-            return ReferenceEquals(foundType, typeof(bool)) ? (bool)value : _converter.ToBoolean(value);
+            object? value = GetElement(name, out foundType);
+            return ReferenceEquals(foundType, typeof(bool)) ? (bool)value : _converter.ToBoolean(value!); // if value is null To* method will either deal with it or throw
         }
 
         public char GetChar(string name)
         {
             Type foundType;
-            object value = GetElement(name, out foundType);
-            return ReferenceEquals(foundType, typeof(char)) ? (char)value : _converter.ToChar(value);
+            object? value = GetElement(name, out foundType);
+            return ReferenceEquals(foundType, typeof(char)) ? (char)value : _converter.ToChar(value!);
         }
 
         [CLSCompliant(false)]
         public sbyte GetSByte(string name)
         {
             Type foundType;
-            object value = GetElement(name, out foundType);
-            return ReferenceEquals(foundType, typeof(sbyte)) ? (sbyte)value : _converter.ToSByte(value);
+            object? value = GetElement(name, out foundType);
+            return ReferenceEquals(foundType, typeof(sbyte)) ? (sbyte)value : _converter.ToSByte(value!);
         }
 
         public byte GetByte(string name)
         {
             Type foundType;
-            object value = GetElement(name, out foundType);
-            return ReferenceEquals(foundType, typeof(byte)) ? (byte)value : _converter.ToByte(value);
+            object? value = GetElement(name, out foundType);
+            return ReferenceEquals(foundType, typeof(byte)) ? (byte)value : _converter.ToByte(value!);
         }
 
         public short GetInt16(string name)
         {
             Type foundType;
-            object value = GetElement(name, out foundType);
-            return ReferenceEquals(foundType, typeof(short)) ? (short)value : _converter.ToInt16(value);
+            object? value = GetElement(name, out foundType);
+            return ReferenceEquals(foundType, typeof(short)) ? (short)value : _converter.ToInt16(value!);
         }
 
         [CLSCompliant(false)]
         public ushort GetUInt16(string name)
         {
             Type foundType;
-            object value = GetElement(name, out foundType);
-            return ReferenceEquals(foundType, typeof(ushort)) ? (ushort)value : _converter.ToUInt16(value);
+            object? value = GetElement(name, out foundType);
+            return ReferenceEquals(foundType, typeof(ushort)) ? (ushort)value : _converter.ToUInt16(value!);
         }
 
         public int GetInt32(string name)
         {
             Type foundType;
-            object value = GetElement(name, out foundType);
-            return ReferenceEquals(foundType, typeof(int)) ? (int)value : _converter.ToInt32(value);
+            object? value = GetElement(name, out foundType);
+            return ReferenceEquals(foundType, typeof(int)) ? (int)value : _converter.ToInt32(value!);
         }
 
         [CLSCompliant(false)]
         public uint GetUInt32(string name)
         {
             Type foundType;
-            object value = GetElement(name, out foundType);
-            return ReferenceEquals(foundType, typeof(uint)) ? (uint)value : _converter.ToUInt32(value);
+            object? value = GetElement(name, out foundType);
+            return ReferenceEquals(foundType, typeof(uint)) ? (uint)value : _converter.ToUInt32(value!);
         }
 
         public long GetInt64(string name)
         {
             Type foundType;
-            object value = GetElement(name, out foundType);
-            return ReferenceEquals(foundType, typeof(long)) ? (long)value : _converter.ToInt64(value);
+            object? value = GetElement(name, out foundType);
+            return ReferenceEquals(foundType, typeof(long)) ? (long)value : _converter.ToInt64(value!);
         }
 
         [CLSCompliant(false)]
         public ulong GetUInt64(string name)
         {
             Type foundType;
-            object value = GetElement(name, out foundType);
-            return ReferenceEquals(foundType, typeof(ulong)) ? (ulong)value : _converter.ToUInt64(value);
+            object? value = GetElement(name, out foundType);
+            return ReferenceEquals(foundType, typeof(ulong)) ? (ulong)value : _converter.ToUInt64(value!);
         }
 
         public float GetSingle(string name)
         {
             Type foundType;
-            object value = GetElement(name, out foundType);
-            return ReferenceEquals(foundType, typeof(float)) ? (float)value : _converter.ToSingle(value);
+            object? value = GetElement(name, out foundType);
+            return ReferenceEquals(foundType, typeof(float)) ? (float)value : _converter.ToSingle(value!);
         }
 
 
         public double GetDouble(string name)
         {
             Type foundType;
-            object value = GetElement(name, out foundType);
-            return ReferenceEquals(foundType, typeof(double)) ? (double)value : _converter.ToDouble(value);
+            object? value = GetElement(name, out foundType);
+            return ReferenceEquals(foundType, typeof(double)) ? (double)value : _converter.ToDouble(value!);
         }
 
         public decimal GetDecimal(string name)
         {
             Type foundType;
-            object value = GetElement(name, out foundType);
-            return ReferenceEquals(foundType, typeof(decimal)) ? (decimal)value : _converter.ToDecimal(value);
+            object? value = GetElement(name, out foundType);
+            return ReferenceEquals(foundType, typeof(decimal)) ? (decimal)value : _converter.ToDecimal(value!);
         }
 
         public DateTime GetDateTime(string name)
         {
             Type foundType;
-            object value = GetElement(name, out foundType);
-            return ReferenceEquals(foundType, typeof(DateTime)) ? (DateTime)value : _converter.ToDateTime(value);
+            object? value = GetElement(name, out foundType);
+            return ReferenceEquals(foundType, typeof(DateTime)) ? (DateTime)value : _converter.ToDateTime(value!);
         }
 
-        public string GetString(string name)
+        public string? GetString(string name)
         {
             Type foundType;
-            object value = GetElement(name, out foundType);
-            return ReferenceEquals(foundType, typeof(string)) || value == null ? (string)value : _converter.ToString(value);
+            object? value = GetElement(name, out foundType);
+            return ReferenceEquals(foundType, typeof(string)) || value == null ? (string?)value : _converter.ToString(value);
         }
     }
 }
index ba84e65..9ce2080 100644 (file)
@@ -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.Collections;
 using System.Diagnostics;
 
@@ -10,17 +11,17 @@ namespace System.Runtime.Serialization
     public readonly struct SerializationEntry
     {
         private readonly string _name;
-        private readonly object _value;
+        private readonly object? _value;
         private readonly Type _type;
 
-        internal SerializationEntry(string entryName, object entryValue, Type entryType)
+        internal SerializationEntry(string entryName, object? entryValue, Type entryType)
         {
             _name = entryName;
             _value = entryValue;
             _type = entryType;
         }
 
-        public object Value => _value;
+        public object? Value => _value;
         public string Name => _name;
         public Type ObjectType => _type;
     }
@@ -28,13 +29,13 @@ namespace System.Runtime.Serialization
     public sealed class SerializationInfoEnumerator : IEnumerator
     {
         private readonly string[] _members;
-        private readonly object[] _data;
+        private readonly object?[] _data;
         private readonly Type[] _types;
         private readonly int _numItems;
         private int _currItem;
         private bool _current;
 
-        internal SerializationInfoEnumerator(string[] members, object[] info, Type[] types, int numItems)
+        internal SerializationInfoEnumerator(string[] members, object?[] info, Type[] types, int numItems)
         {
             Debug.Assert(members != null, "[SerializationInfoEnumerator.ctor]members!=null");
             Debug.Assert(info != null, "[SerializationInfoEnumerator.ctor]info!=null");
@@ -70,7 +71,7 @@ namespace System.Runtime.Serialization
             return _current;
         }
 
-        object IEnumerator.Current => Current;
+        object? IEnumerator.Current => Current; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/23268
 
         public SerializationEntry Current
         {
@@ -101,7 +102,7 @@ namespace System.Runtime.Serialization
                 return _members[_currItem];
             }
         }
-        public object Value
+        public object? Value
         {
             get
             {
index cdcb1c3..e67f307 100644 (file)
@@ -2,24 +2,25 @@
 // 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.Serialization
 {
     public readonly struct StreamingContext
     {
-        private readonly object _additionalContext;
+        private readonly object? _additionalContext;
         private readonly StreamingContextStates _state;
 
         public StreamingContext(StreamingContextStates state) : this(state, null)
         {
         }
 
-        public StreamingContext(StreamingContextStates state, object additional)
+        public StreamingContext(StreamingContextStates state, object? additional)
         {
             _state = state;
             _additionalContext = additional;
         }
 
-        public override bool Equals(object obj)
+        public override bool Equals(object? obj)
         {
             if (!(obj is StreamingContext))
             {
@@ -33,7 +34,7 @@ namespace System.Runtime.Serialization
 
         public StreamingContextStates State => _state;
 
-        public object Context => _additionalContext;
+        public object? Context => _additionalContext;
     }
 
     [Flags]
index f149475..b6156ca 100644 (file)
@@ -55,12 +55,12 @@ namespace System.Security
         protected SecurityException(SerializationInfo info, StreamingContext context)
             : base(info, context)
         {
-            Demanded = (string)info.GetValueNoThrow(DemandedName, typeof(string));
-            GrantedSet = (string)info.GetValueNoThrow(GrantedSetName, typeof(string));
-            RefusedSet = (string)info.GetValueNoThrow(RefusedSetName, typeof(string));
-            DenySetInstance = (string)info.GetValueNoThrow(DeniedName, typeof(string));
-            PermitOnlySetInstance = (string)info.GetValueNoThrow(PermitOnlyName, typeof(string));
-            Url = (string)info.GetValueNoThrow(UrlName, typeof(string));
+            Demanded = (string?)info.GetValueNoThrow(DemandedName, typeof(string));
+            GrantedSet = (string?)info.GetValueNoThrow(GrantedSetName, typeof(string));
+            RefusedSet = (string?)info.GetValueNoThrow(RefusedSetName, typeof(string));
+            DenySetInstance = (string?)info.GetValueNoThrow(DeniedName, typeof(string));
+            PermitOnlySetInstance = (string?)info.GetValueNoThrow(PermitOnlyName, typeof(string));
+            Url = (string?)info.GetValueNoThrow(UrlName, typeof(string));
         }
 
         public override string ToString() => base.ToString();
index e982a38..4ffb838 100644 (file)
@@ -189,7 +189,7 @@ namespace System
 
         private CultureAwareComparer(SerializationInfo info, StreamingContext context)
         {
-            _compareInfo = (CompareInfo)info.GetValue("_compareInfo", typeof(CompareInfo));
+            _compareInfo = (CompareInfo)info.GetValue("_compareInfo", typeof(CompareInfo))!;
             bool ignoreCase = info.GetBoolean("_ignoreCase");
 
             var obj = info.GetValueNoThrow("_options", typeof(CompareOptions));
index c3c2c50..3a5c26f 100644 (file)
@@ -255,7 +255,7 @@ namespace System
                 _daylightTransitionStart = (TransitionTime)info.GetValue("DaylightTransitionStart", typeof(TransitionTime)); // Do not rename (binary serialization)
                 _daylightTransitionEnd = (TransitionTime)info.GetValue("DaylightTransitionEnd", typeof(TransitionTime)); // Do not rename (binary serialization)
 
-                object o = info.GetValueNoThrow("BaseUtcOffsetDelta", typeof(TimeSpan)); // Do not rename (binary serialization)
+                object? o = info.GetValueNoThrow("BaseUtcOffsetDelta", typeof(TimeSpan)); // Do not rename (binary serialization)
                 if (o != null)
                 {
                     _baseUtcOffsetDelta = (TimeSpan)o;
index 0e831d1..02543cc 100644 (file)
@@ -259,7 +259,7 @@ namespace System
             {
                 using (StreamReader sr = new StreamReader(Path.Combine(timeZoneDirectory, ZoneTabFileName), Encoding.UTF8))
                 {
-                    string zoneTabFileLine;
+                    string? zoneTabFileLine;
                     while ((zoneTabFileLine = sr.ReadLine()) != null)
                     {
                         if (!string.IsNullOrEmpty(zoneTabFileLine) && zoneTabFileLine[0] != '#')
index 3245845..617ee9a 100644 (file)
@@ -1048,12 +1048,12 @@ namespace System
                 throw new ArgumentNullException(nameof(info));\r
             }\r
 \r
-            _id = (string)info.GetValue("Id", typeof(string)); // Do not rename (binary serialization)\r
-            _displayName = (string)info.GetValue("DisplayName", typeof(string)); // Do not rename (binary serialization)\r
-            _standardDisplayName = (string)info.GetValue("StandardName", typeof(string)); // Do not rename (binary serialization)\r
-            _daylightDisplayName = (string)info.GetValue("DaylightName", typeof(string)); // Do not rename (binary serialization)\r
+            _id = (string)info.GetValue("Id", typeof(string))!; // Do not rename (binary serialization)\r
+            _displayName = (string?)info.GetValue("DisplayName", typeof(string)); // Do not rename (binary serialization)\r
+            _standardDisplayName = (string?)info.GetValue("StandardName", typeof(string)); // Do not rename (binary serialization)\r
+            _daylightDisplayName = (string?)info.GetValue("DaylightName", typeof(string)); // Do not rename (binary serialization)\r
             _baseUtcOffset = (TimeSpan)info.GetValue("BaseUtcOffset", typeof(TimeSpan)); // Do not rename (binary serialization)\r
-            _adjustmentRules = (AdjustmentRule[])info.GetValue("AdjustmentRules", typeof(AdjustmentRule[])); // Do not rename (binary serialization)\r
+            _adjustmentRules = (AdjustmentRule[]?)info.GetValue("AdjustmentRules", typeof(AdjustmentRule[])); // Do not rename (binary serialization)\r
             _supportsDaylightSavingTime = (bool)info.GetValue("SupportsDaylightSavingTime", typeof(bool)); // Do not rename (binary serialization)\r
         }\r
 \r
index c5d61f2..6ebbb8a 100644 (file)
@@ -17,7 +17,7 @@ namespace System
     {
         internal const int NullUnity = 0x0002;
         private readonly int _unityType;
-        private readonly string _data;
+        private readonly string? _data;
 
         /// <summary>
         /// A helper method that returns the SerializationInfo that a class utilizing 
index 097f47a..2353afa 100644 (file)
@@ -2,10 +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;
-using System.Diagnostics;
-using System.IO;
-using System.Reflection;
 using System.Runtime.InteropServices;
 using System.Runtime.Loader;
 
@@ -23,9 +21,15 @@ namespace Internal.Runtime.InteropServices
         /// <param name="assemblyPath">The path to the assembly (as a pointer to a UTF-16 C string).</param>
         public static unsafe void LoadInMemoryAssembly(IntPtr moduleHandle, IntPtr assemblyPath)
         {
+            string? assemblyPathString = Marshal.PtrToStringUni(assemblyPath);
+            if (assemblyPathString == null)
+            {
+                throw new ArgumentOutOfRangeException(nameof(assemblyPath));
+            }
+
             // We don't cache the ALCs here since each IJW assembly will call this method at most once
             // (the load process rewrites the stubs that call here to call the actual methods they're supposed to)
-            AssemblyLoadContext context = new IsolatedComponentLoadContext(Marshal.PtrToStringUni(assemblyPath));
+            AssemblyLoadContext context = new IsolatedComponentLoadContext(assemblyPathString);
             context.LoadFromInMemoryModule(moduleHandle);
         }
     }
index d78d7dd..49a480e 100644 (file)
@@ -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;
 using System.Reflection;
 using System.Runtime.Loader;
@@ -13,7 +14,7 @@ namespace Internal.Runtime.InteropServices
     /// or IJW components loaded from native. It provides a load context that uses an <see cref="AssemblyDependencyResolver" /> to resolve the component's
     /// dependencies within the ALC and not pollute the default ALC.
     ///</summary>
-    internal class IsolatedComponentLoadContext : AssemblyLoadContext
+    internal sealed class IsolatedComponentLoadContext : AssemblyLoadContext
     {
         private readonly AssemblyDependencyResolver _resolver;
 
@@ -22,9 +23,9 @@ namespace Internal.Runtime.InteropServices
             _resolver = new AssemblyDependencyResolver(componentAssemblyPath);
         }
 
-        protected override Assembly Load(AssemblyName assemblyName)
+        protected override Assembly? Load(AssemblyName assemblyName)
         {
-            string assemblyPath = _resolver.ResolveAssemblyToPath(assemblyName);
+            string? assemblyPath = _resolver.ResolveAssemblyToPath(assemblyName);
             if (assemblyPath != null)
             {
                 return LoadFromAssemblyPath(assemblyPath);
@@ -35,7 +36,7 @@ namespace Internal.Runtime.InteropServices
 
         protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
         {
-            string libraryPath = _resolver.ResolveUnmanagedDllToPath(unmanagedDllName);
+            string? libraryPath = _resolver.ResolveUnmanagedDllToPath(unmanagedDllName);
             if (libraryPath != null)
             {
                 return LoadUnmanagedDllFromPath(libraryPath);
index eb1c584..8f94666 100644 (file)
@@ -2,11 +2,9 @@
 // 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.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Reflection;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.WindowsRuntime;
 using System.Runtime.Loader;
@@ -44,7 +42,7 @@ namespace Internal.Runtime.InteropServices.WindowsRuntime
         public unsafe static int GetActivationFactory(
             char* componentPath,
             [MarshalAs(UnmanagedType.HString)] string typeName,
-            [MarshalAs(UnmanagedType.Interface)] out IActivationFactory activationFactory)
+            [MarshalAs(UnmanagedType.Interface)] out IActivationFactory? activationFactory)
         {
             activationFactory = null;
             try
@@ -54,7 +52,7 @@ namespace Internal.Runtime.InteropServices.WindowsRuntime
                     throw new ArgumentNullException(nameof(typeName));
                 }
 
-                AssemblyLoadContext context = GetALC(Marshal.PtrToStringUni((IntPtr)componentPath));
+                AssemblyLoadContext context = GetALC(Marshal.PtrToStringUni((IntPtr)componentPath)!);
                 
                 Type winRTType = context.LoadTypeForWinRTTypeNameInContext(typeName);
 
index da7cbf2..c7f5b1d 100644 (file)
@@ -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
 internal static partial class Interop
 {
     internal static partial class Libraries
index 897e530..9faf292 100644 (file)
@@ -24,7 +24,7 @@ namespace System
             // We use the no throw version since we could be deserializing a pre-V4
             // exception object that may not have this entry. In such a case, we would
             // get null.
-            _watsonBuckets = (object)info.GetValueNoThrow("WatsonBuckets", typeof(byte[])); // Do not rename (binary serialization)
+            _watsonBuckets = info.GetValueNoThrow("WatsonBuckets", typeof(byte[])); // Do not rename (binary serialization)
 
             // If we are constructing a new exception after a cross-appdomain call...
             if (context.State == StreamingContextStates.CrossAppDomain)
index 95a54fd..d1bc0f4 100644 (file)
@@ -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.Globalization
 {
     internal sealed partial class GlobalizationMode
index 2738d5b..ebfa25f 100644 (file)
@@ -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.Globalization
 {
     internal sealed partial class GlobalizationMode
index 57f3581..c1ad15f 100644 (file)
@@ -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.Globalization
 {
     internal sealed partial class GlobalizationMode
@@ -18,7 +19,7 @@ namespace System.Globalization
             if (!exist)
             {
                 // Linux doesn't support environment variable names include dots
-                string switchValue = Environment.GetEnvironmentVariable("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT");
+                string? switchValue = Environment.GetEnvironmentVariable("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT");
                 if (switchValue != null)
                 {
                     ret = bool.IsTrueStringIgnoreCase(switchValue) || switchValue.Equals("1");
index 2b6e5b2..5841e95 100644 (file)
@@ -2,9 +2,9 @@
 // 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.CompilerServices;
 using System.Runtime.InteropServices;
-using System.Security;
 
 namespace System.Reflection.Metadata
 {
index c398987..c6c8dab 100644 (file)
@@ -2,10 +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.Text;
-
+#nullable enable
 namespace System.Runtime.InteropServices.CustomMarshalers
 {
     internal static class ComDataHelpers
@@ -22,7 +19,7 @@ namespace System.Runtime.InteropServices.CustomMarshalers
             managedView = createCallback((T)comObject);
             if (!Marshal.SetComObjectData(comObject, key, managedView))
             {
-                managedView = (TView)Marshal.GetComObjectData(comObject, key);
+                managedView = (TView)Marshal.GetComObjectData(comObject, key)!;
             }
             return managedView;
         }
index b3d319a..332a885 100644 (file)
@@ -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.Collections;
 
 namespace System.Runtime.InteropServices.CustomMarshalers
index 68a9bb8..4fcff0a 100644 (file)
@@ -1,6 +1,8 @@
 // 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.Collections.Generic;
 using System.IO;
 using System.Reflection;
@@ -29,9 +31,14 @@ namespace System.Runtime.Loader
 
         public AssemblyDependencyResolver(string componentAssemblyPath)
         {
-            string assemblyPathsList = null;
-            string nativeSearchPathsList = null;
-            string resourceSearchPathsList = null;
+            if (componentAssemblyPath == null)
+            {
+                throw new ArgumentNullException(nameof(componentAssemblyPath));
+            }
+
+            string? assemblyPathsList = null;
+            string? nativeSearchPathsList = null;
+            string? resourceSearchPathsList = null;
             int returnCode = 0;
 
             StringBuilder errorMessage = new StringBuilder();
@@ -93,17 +100,22 @@ namespace System.Runtime.Loader
             _assemblyPaths = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
             foreach (string assemblyPath in assemblyPaths)
             {
-                _assemblyPaths.Add(Path.GetFileNameWithoutExtension(assemblyPath), assemblyPath);
+                _assemblyPaths.Add(Path.GetFileNameWithoutExtension(assemblyPath)!, assemblyPath); // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
             }
 
             _nativeSearchPaths = SplitPathsList(nativeSearchPathsList);
             _resourceSearchPaths = SplitPathsList(resourceSearchPathsList);
 
-            _assemblyDirectorySearchPaths = new string[1] { Path.GetDirectoryName(componentAssemblyPath) };
+            _assemblyDirectorySearchPaths = new string[1] { Path.GetDirectoryName(componentAssemblyPath)! }; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
         }
 
-        public string ResolveAssemblyToPath(AssemblyName assemblyName)
+        public string? ResolveAssemblyToPath(AssemblyName assemblyName)
         {
+            if (assemblyName == null)
+            {
+                throw new ArgumentNullException(nameof(assemblyName));
+            }
+
             // Determine if the assembly name is for a satellite assembly or not
             // This is the same logic as in AssemblyBinder::BindByTpaList in CoreCLR
             // - If the culture name is non-empty and it's not 'neutral' 
@@ -130,7 +142,7 @@ namespace System.Runtime.Loader
                     }
                 }
             }
-            else
+            else if (assemblyName.Name != null)
             {
                 // Load code assembly - simply look it up in the dictionary by its simple name.
                 if (_assemblyPaths.TryGetValue(assemblyName.Name, out string assemblyPath))
@@ -148,8 +160,13 @@ namespace System.Runtime.Loader
             return null;
         }
 
-        public string ResolveUnmanagedDllToPath(string unmanagedDllName)
+        public string? ResolveUnmanagedDllToPath(string unmanagedDllName)
         {
+            if (unmanagedDllName == null)
+            {
+                throw new ArgumentNullException(nameof(unmanagedDllName));
+            }
+
             string[] searchPaths;
             if (unmanagedDllName.Contains(Path.DirectorySeparatorChar))
             {
@@ -180,7 +197,7 @@ namespace System.Runtime.Loader
             return null;
         }
 
-        private static string[] SplitPathsList(string pathsList)
+        private static string[] SplitPathsList(string? pathsList)
         {
             if (pathsList == null)
             {
index 64a38a9..7000103 100644 (file)
@@ -57,7 +57,7 @@ namespace System
                 throw new ArgumentNullException(nameof(info));
             }
 
-            object target = info.GetValue("TrackedObject", typeof(object)); // Do not rename (binary serialization)
+            object? target = info.GetValue("TrackedObject", typeof(object)); // Do not rename (binary serialization)
             bool trackResurrection = info.GetBoolean("TrackResurrection"); // Do not rename (binary serialization)
 
             Create(target, trackResurrection);
index fb26126..d1c75ce 100644 (file)
@@ -52,7 +52,7 @@ namespace System
                 throw new ArgumentNullException(nameof(info));
             }
 
-            T target = (T)info.GetValue("TrackedObject", typeof(T)); // Do not rename (binary serialization)
+            T target = (T)info.GetValue("TrackedObject", typeof(T))!; // Do not rename (binary serialization) // TODO-NULLABLE-GENERIC
             bool trackResurrection = info.GetBoolean("TrackResurrection"); // Do not rename (binary serialization)
 
             Create(target, trackResurrection);