diff options
author | Stephen Toub <stoub@microsoft.com> | 2019-06-13 10:03:40 -0400 |
---|---|---|
committer | Stephen Toub <stoub@microsoft.com> | 2019-06-13 23:38:44 -0400 |
commit | 64ca544ecf55490675e72b853e98ebc8cc75a4fe (patch) | |
tree | 7b6b0fdc0bb2302ca93bb0704a624d17d709fd0e | |
parent | e783e68adf65090eb4c701bfccb53294b8a0a596 (diff) | |
download | coreclr-64ca544ecf55490675e72b853e98ebc8cc75a4fe.tar.gz coreclr-64ca544ecf55490675e72b853e98ebc8cc75a4fe.tar.bz2 coreclr-64ca544ecf55490675e72b853e98ebc8cc75a4fe.zip |
Update Corelib to adapt to compiler nullability updates
38 files changed, 97 insertions, 107 deletions
diff --git a/src/System.Private.CoreLib/shared/Internal/Win32/RegistryKey.cs b/src/System.Private.CoreLib/shared/Internal/Win32/RegistryKey.cs index 6f4c31255c..cec8e2f32d 100644 --- a/src/System.Private.CoreLib/shared/Internal/Win32/RegistryKey.cs +++ b/src/System.Private.CoreLib/shared/Internal/Win32/RegistryKey.cs @@ -371,7 +371,7 @@ namespace Internal.Win32 // make sure the string is null terminated before processing the data if (blob.Length > 0 && blob[blob.Length - 1] != (char)0) { - Array.Resize(ref blob!, blob.Length + 1); // TODO-NULLABLE: Remove ! when nullable attributes are respected + Array.Resize(ref blob, blob.Length + 1); } string[] strings = Array.Empty<string>(); @@ -416,13 +416,13 @@ namespace Internal.Win32 { if (strings.Length == stringsCount) { - Array.Resize(ref strings!, stringsCount > 0 ? stringsCount * 2 : 4); // TODO-NULLABLE: Remove ! when nullable attributes are respected + Array.Resize(ref strings, stringsCount > 0 ? stringsCount * 2 : 4); } strings[stringsCount++] = toAdd; } } - Array.Resize(ref strings!, stringsCount); // TODO-NULLABLE: Remove ! when nullable attributes are respected + Array.Resize(ref strings, stringsCount); data = strings; } break; diff --git a/src/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.MountPoints.cs b/src/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.MountPoints.cs index a2fe2078b6..134dcb9203 100644 --- a/src/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.MountPoints.cs +++ b/src/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.MountPoints.cs @@ -27,13 +27,13 @@ internal static partial class Interop { if (count == found.Length) { - Array.Resize(ref found!, count * 2); // TODO-NULLABLE: Remove ! when nullable attributes are respected + Array.Resize(ref found, count * 2); } found[count++] = Marshal.PtrToStringAnsi((IntPtr)name)!; }); } - Array.Resize(ref found!, count); // TODO-NULLABLE: Remove ! when nullable attributes are respected + Array.Resize(ref found, count); return found; } } diff --git a/src/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs b/src/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs index fbd6ac7cee..fc4d875289 100644 --- a/src/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs +++ b/src/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs @@ -675,7 +675,7 @@ namespace System.Collections.Generic public virtual void OnDeserialization(object? sender) { - HashHelpers.SerializationInfoTable.TryGetValue(this, out SerializationInfo siInfo); + HashHelpers.SerializationInfoTable.TryGetValue(this, out SerializationInfo? siInfo); if (siInfo == null) { diff --git a/src/System.Private.CoreLib/shared/System/Collections/Hashtable.cs b/src/System.Private.CoreLib/shared/System/Collections/Hashtable.cs index f5a90e654e..b74de8225b 100644 --- a/src/System.Private.CoreLib/shared/System/Collections/Hashtable.cs +++ b/src/System.Private.CoreLib/shared/System/Collections/Hashtable.cs @@ -1161,7 +1161,7 @@ namespace System.Collections return; } - SerializationInfo siInfo; + SerializationInfo? siInfo; HashHelpers.SerializationInfoTable.TryGetValue(this, out siInfo); if (siInfo == null) diff --git a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/CounterGroup.cs b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/CounterGroup.cs index d669114d50..0879f9d9f4 100644 --- a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/CounterGroup.cs +++ b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/CounterGroup.cs @@ -52,11 +52,9 @@ namespace System.Diagnostics.Tracing { if (e.Command == EventCommand.Enable || e.Command == EventCommand.Update) { - string valueStr; - float value; Debug.Assert(e.Arguments != null); - if (e.Arguments.TryGetValue("EventCounterIntervalSec", out valueStr) && float.TryParse(valueStr, out value)) + if (e.Arguments.TryGetValue("EventCounterIntervalSec", out string? valueStr) && float.TryParse(valueStr, out float value)) { lock (this) // Lock the CounterGroup { diff --git a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs index a914b930a1..d06e292e8f 100644 --- a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs +++ b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs @@ -1734,7 +1734,7 @@ namespace System.Diagnostics.Tracing hash.Start(); hash.Append(namespaceBytes); hash.Append(bytes); - Array.Resize(ref bytes!, 16); // TODO-NULLABLE: Remove ! when nullable attributes are respected + Array.Resize(ref bytes, 16); hash.Finish(bytes); bytes[7] = unchecked((byte)((bytes[7] & 0x0F) | 0x50)); // Set high 4 bits of octet 7 to 5, as per RFC 4122 @@ -5446,8 +5446,8 @@ namespace System.Diagnostics.Tracing { ManifestError(SR.Format(SR.EventSource_IllegalOpcodeValue, name, value)); } - string prevName; - if (opcodeTab.TryGetValue(value, out prevName) && !name.Equals(prevName, StringComparison.Ordinal)) + + if (opcodeTab.TryGetValue(value, out string? prevName) && !name.Equals(prevName, StringComparison.Ordinal)) { ManifestError(SR.Format(SR.EventSource_OpcodeCollision, name, prevName, value)); } @@ -5462,8 +5462,8 @@ namespace System.Diagnostics.Tracing { ManifestError(SR.Format(SR.EventSource_IllegalTaskValue, name, value)); } - string prevName; - if (taskTab != null && taskTab.TryGetValue(value, out prevName) && !name.Equals(prevName, StringComparison.Ordinal)) + + if (taskTab != null && taskTab.TryGetValue(value, out string? prevName) && !name.Equals(prevName, StringComparison.Ordinal)) { ManifestError(SR.Format(SR.EventSource_TaskCollision, name, prevName, value)); } @@ -5484,8 +5484,8 @@ namespace System.Diagnostics.Tracing { ManifestError(SR.Format(SR.EventSource_IllegalKeywordsValue, name, "0x" + value.ToString("x", CultureInfo.CurrentCulture))); } - string prevName; - if (keywordTab != null && keywordTab.TryGetValue(value, out prevName) && !name.Equals(prevName, StringComparison.Ordinal)) + + if (keywordTab != null && keywordTab.TryGetValue(value, out string? prevName) && !name.Equals(prevName, StringComparison.Ordinal)) { ManifestError(SR.Format(SR.EventSource_KeywordCollision, name, prevName, "0x" + value.ToString("x", CultureInfo.CurrentCulture))); } @@ -5652,10 +5652,9 @@ namespace System.Diagnostics.Tracing // at this point we have all the information we need to translate the C# Message // to the manifest string we'll put in the stringTab - string msg; - if (stringTab.TryGetValue("event_" + eventName, out msg)) + if (stringTab.TryGetValue("event_" + eventName, out string? msg)) { - msg = TranslateToManifestConvention(msg!, eventName); // https://github.com/dotnet/roslyn/issues/26761 + msg = TranslateToManifestConvention(msg, eventName); stringTab["event_" + eventName] = msg; } @@ -5687,7 +5686,7 @@ namespace System.Diagnostics.Tracing if (channelTab.Count == MaxCountChannels) ManifestError(SR.EventSource_MaxChannelExceeded); - ChannelInfo info; + ChannelInfo? info; if (!channelTab.TryGetValue((int)channel, out info)) { // If we were not given an explicit channel, allocate one. @@ -5967,8 +5966,8 @@ namespace System.Diagnostics.Tracing return; stringBuilder.Append(" message=\"$(string.").Append(key).Append(")\""); - string prevValue; - if (stringTab.TryGetValue(key, out prevValue) && !prevValue.Equals(value)) + + if (stringTab.TryGetValue(key, out string? prevValue) && !prevValue.Equals(value)) { ManifestError(SR.Format(SR.EventSource_DuplicateStringKey, key), true); return; @@ -6045,7 +6044,7 @@ namespace System.Diagnostics.Tracing if (resources != null && eventMessage == null) eventMessage = resources.GetString("event_" + eventName, CultureInfo.InvariantCulture); - Debug.Assert(info.Attribs != null); + Debug.Assert(info!.Attribs != null); if (info.Attribs.EventChannelType == EventChannelType.Admin && eventMessage == null) ManifestError(SR.Format(SR.EventSource_EventWithAdminChannelMustHaveMessage, eventName, info.Name)); return info.Name; @@ -6056,7 +6055,7 @@ namespace System.Diagnostics.Tracing if (task == EventTask.None) return ""; - string ret; + string? ret; if (taskTab == null) taskTab = new Dictionary<int, string>(); if (!taskTab.TryGetValue((int)task, out ret)) @@ -6209,14 +6208,14 @@ namespace System.Diagnostics.Tracing if (stringBuilder == null) return eventMessage; UpdateStringBuilder(ref stringBuilder, eventMessage, writtenSoFar, i - writtenSoFar); - return stringBuilder!.ToString(); // TODO-NULLABLE: Remove ! when nullable attributes are respected + return stringBuilder.ToString(); } if (eventMessage[i] == '%') { // handle format message escaping character '%' by escaping it UpdateStringBuilder(ref stringBuilder, eventMessage, writtenSoFar, i - writtenSoFar); - stringBuilder!.Append("%%"); // TODO-NULLABLE: Remove ! when nullable attributes are respected + stringBuilder.Append("%%"); i++; writtenSoFar = i; } @@ -6225,7 +6224,7 @@ namespace System.Diagnostics.Tracing { // handle C# escaped '{" and '}' UpdateStringBuilder(ref stringBuilder, eventMessage, writtenSoFar, i - writtenSoFar); - stringBuilder!.Append(eventMessage[i]); // TODO-NULLABLE: Remove ! when nullable attributes are respected + stringBuilder.Append(eventMessage[i]); i++; i++; writtenSoFar = i; } @@ -6244,7 +6243,7 @@ namespace System.Diagnostics.Tracing i++; UpdateStringBuilder(ref stringBuilder, eventMessage, writtenSoFar, leftBracket - writtenSoFar); int manIndex = TranslateIndexToManifestConvention(argNum, evtName); - stringBuilder!.Append('%').Append(manIndex); // TODO-NULLABLE: Remove ! when nullable attributes are respected + stringBuilder.Append('%').Append(manIndex); // An '!' after the insert specifier {n} will be interpreted as a literal. // We'll escape it so that mc.exe does not attempt to consider it the // beginning of a format string. @@ -6264,7 +6263,7 @@ namespace System.Diagnostics.Tracing { UpdateStringBuilder(ref stringBuilder, eventMessage, writtenSoFar, i - writtenSoFar); i++; - stringBuilder!.Append(s_escapes[chIdx]); // TODO-NULLABLE: Remove ! when nullable attributes are respected + stringBuilder.Append(s_escapes[chIdx]); writtenSoFar = i; } else @@ -6274,7 +6273,7 @@ namespace System.Diagnostics.Tracing private int TranslateIndexToManifestConvention(int idx, string evtName) { - List<int> byteArrArgIndices; + List<int>? byteArrArgIndices; if (perEventByteArrayArgIndices.TryGetValue(evtName, out byteArrArgIndices)) { foreach (var byArrIdx in byteArrArgIndices) diff --git a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingTypeInfo.cs b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingTypeInfo.cs index f31765c2f3..45d4f77caa 100644 --- a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingTypeInfo.cs +++ b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingTypeInfo.cs @@ -189,7 +189,7 @@ namespace System.Diagnostics.Tracing { var cache = threadCache ?? (threadCache = new Dictionary<Type, TraceLoggingTypeInfo>()); - TraceLoggingTypeInfo instance; + TraceLoggingTypeInfo? instance; if (!cache.TryGetValue(type, out instance)) { if (recursionCheck == null) diff --git a/src/System.Private.CoreLib/shared/System/Environment.Unix.cs b/src/System.Private.CoreLib/shared/System/Environment.Unix.cs index 0d802dcec9..9a2af4dfb8 100644 --- a/src/System.Private.CoreLib/shared/System/Environment.Unix.cs +++ b/src/System.Private.CoreLib/shared/System/Environment.Unix.cs @@ -75,16 +75,14 @@ namespace System { Debug.Assert(option == SpecialFolderOption.Create); -#pragma warning disable CS8634 // TODO-NULLABLE: Remove warning disable when nullable attributes are respected // TODO #11151: Replace with Directory.CreateDirectory once we have access to System.IO.FileSystem here. Func<string, object> createDirectory = LazyInitializer.EnsureInitialized(ref s_directoryCreateDirectory, () => { Type dirType = Type.GetType("System.IO.Directory, System.IO.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", throwOnError: true)!; MethodInfo mi = dirType.GetTypeInfo().GetDeclaredMethod("CreateDirectory")!; return (Func<string, object>)mi.CreateDelegate(typeof(Func<string, object>)); - })!; // TODO-NULLABLE: Remove ! when nullable attributes are respected + }); createDirectory(path); -#pragma warning restore CS8634 return path; } diff --git a/src/System.Private.CoreLib/shared/System/Environment.cs b/src/System.Private.CoreLib/shared/System/Environment.cs index 319ae9b1c6..d99a5a667a 100644 --- a/src/System.Private.CoreLib/shared/System/Environment.cs +++ b/src/System.Private.CoreLib/shared/System/Environment.cs @@ -149,7 +149,7 @@ namespace System versionSpan = versionSpan.Slice(0, separatorIndex); // Return zeros rather then failing if the version string fails to parse - return Version.TryParse(versionSpan, out Version? version) ? version! : new Version(); // TODO-NULLABLE: Remove ! when nullable attributes are respected + return Version.TryParse(versionSpan, out Version? version) ? version : new Version(); } } diff --git a/src/System.Private.CoreLib/shared/System/Globalization/CultureData.cs b/src/System.Private.CoreLib/shared/System/Globalization/CultureData.cs index d29668e173..03875c39c0 100644 --- a/src/System.Private.CoreLib/shared/System/Globalization/CultureData.cs +++ b/src/System.Private.CoreLib/shared/System/Globalization/CultureData.cs @@ -359,7 +359,7 @@ namespace System.Globalization if (retVal == null || (retVal.IsNeutralCulture == true)) { // Not a valid mapping, try the hard coded table - string name; + string? name; if (RegionNames.TryGetValue(cultureName, out name)) { // Make sure we can get culture data for it @@ -590,7 +590,7 @@ namespace System.Globalization { // Check the hash table bool ret; - CultureData retVal; + CultureData? retVal; lock (s_lock) { ret = tempHashTable.TryGetValue(hashName, out retVal); diff --git a/src/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfoScanner.cs b/src/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfoScanner.cs index 2005cf3b73..7b5ae00b69 100644 --- a/src/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfoScanner.cs +++ b/src/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfoScanner.cs @@ -221,8 +221,8 @@ namespace System.Globalization AddIgnorableSymbols("."); return; } - string words; - if (KnownWords.TryGetValue(str, out words) == false) + + if (KnownWords.TryGetValue(str, out _) == false) { if (m_dateWords == null) { diff --git a/src/System.Private.CoreLib/shared/System/Globalization/JapaneseCalendar.Win32.cs b/src/System.Private.CoreLib/shared/System/Globalization/JapaneseCalendar.Win32.cs index ffea420e7c..f717adbfe3 100644 --- a/src/System.Private.CoreLib/shared/System/Globalization/JapaneseCalendar.Win32.cs +++ b/src/System.Private.CoreLib/shared/System/Globalization/JapaneseCalendar.Win32.cs @@ -92,10 +92,10 @@ namespace System.Globalization Array.Resize(ref registryEraRanges, iFoundEras); // Sort them - Array.Sort(registryEraRanges!, CompareEraRanges); // TODO-NULLABLE: Remove ! when nullable attributes are respected + Array.Sort(registryEraRanges, CompareEraRanges); // Clean up era information - for (int i = 0; i < registryEraRanges!.Length; i++) // TODO-NULLABLE: Remove ! when nullable attributes are respected + for (int i = 0; i < registryEraRanges.Length; i++) { // eras count backwards from length to 1 (and are 1 based indexes into string arrays) registryEraRanges[i].era = registryEraRanges.Length - i; diff --git a/src/System.Private.CoreLib/shared/System/Globalization/JapaneseLunisolarCalendar.cs b/src/System.Private.CoreLib/shared/System/Globalization/JapaneseLunisolarCalendar.cs index cdaded6bc3..34631e261e 100644 --- a/src/System.Private.CoreLib/shared/System/Globalization/JapaneseLunisolarCalendar.cs +++ b/src/System.Private.CoreLib/shared/System/Globalization/JapaneseLunisolarCalendar.cs @@ -201,7 +201,7 @@ namespace System.Globalization // If we didn't copy any then something was wrong, just return base if (newIndex == 0) return baseEras; - Array.Resize(ref newEras!, newIndex); // TODO-NULLABLE: Remove ! when nullable attributes are respected + Array.Resize(ref newEras!, newIndex); return newEras; } diff --git a/src/System.Private.CoreLib/shared/System/IO/Stream.cs b/src/System.Private.CoreLib/shared/System/IO/Stream.cs index 3b63d17a3c..4b3b0d3a06 100644 --- a/src/System.Private.CoreLib/shared/System/IO/Stream.cs +++ b/src/System.Private.CoreLib/shared/System/IO/Stream.cs @@ -42,7 +42,7 @@ namespace System.IO { // Lazily-initialize _asyncActiveSemaphore. As we're never accessing the SemaphoreSlim's // WaitHandle, we don't need to worry about Disposing it. - return LazyInitializer.EnsureInitialized<SemaphoreSlim>(ref _asyncActiveSemaphore!, () => new SemaphoreSlim(1, 1)); // TODO-NULLABLE: Remove ! when nullable attributes are respected + return LazyInitializer.EnsureInitialized(ref _asyncActiveSemaphore, () => new SemaphoreSlim(1, 1)); } public abstract bool CanRead @@ -1061,7 +1061,7 @@ namespace System.IO { get { - return LazyInitializer.EnsureInitialized<ManualResetEvent>(ref _waitHandle!, () => new ManualResetEvent(true)); // Remove ! when nullable attributes are respected + return LazyInitializer.EnsureInitialized(ref _waitHandle, () => new ManualResetEvent(true)); } } diff --git a/src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs b/src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs index 569c5f5c8c..69820dea99 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs @@ -235,7 +235,7 @@ namespace System.Reflection string normalizedPath = Path.GetFullPath(path); - Assembly result; + Assembly? result; lock (s_loadfile) { if (s_loadfile.TryGetValue(normalizedPath, out result)) diff --git a/src/System.Private.CoreLib/shared/System/Resources/ResourceManager.cs b/src/System.Private.CoreLib/shared/System/Resources/ResourceManager.cs index fbc13b04a3..49e8027ce3 100644 --- a/src/System.Private.CoreLib/shared/System/Resources/ResourceManager.cs +++ b/src/System.Private.CoreLib/shared/System/Resources/ResourceManager.cs @@ -400,7 +400,7 @@ namespace System.Resources throw new ArgumentNullException(nameof(culture)); Dictionary<string, ResourceSet>? localResourceSets = _resourceSets; - ResourceSet rs; + ResourceSet? rs; if (localResourceSets != null) { lock (localResourceSets) @@ -509,7 +509,7 @@ namespace System.Resources lock (localResourceSets) { // If another thread added this culture, return that. - ResourceSet lostRace; + ResourceSet? lostRace; if (localResourceSets.TryGetValue(cultureName, out lostRace)) { if (!object.ReferenceEquals(lostRace, rs)) diff --git a/src/System.Private.CoreLib/shared/System/Resources/ResourceReader.Core.cs b/src/System.Private.CoreLib/shared/System/Resources/ResourceReader.Core.cs index 36e0f89b21..de6cd86521 100644 --- a/src/System.Private.CoreLib/shared/System/Resources/ResourceReader.Core.cs +++ b/src/System.Private.CoreLib/shared/System/Resources/ResourceReader.Core.cs @@ -67,11 +67,11 @@ namespace System.Resources private void InitializeBinaryFormatter() { - LazyInitializer.EnsureInitialized<Type>(ref s_binaryFormatterType!, () => // TODO-NULLABLE: Remove ! when nullable attributes are respected + LazyInitializer.EnsureInitialized(ref s_binaryFormatterType, () => Type.GetType("System.Runtime.Serialization.Formatters.Binary.BinaryFormatter, System.Runtime.Serialization.Formatters, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", throwOnError: true)!); - LazyInitializer.EnsureInitialized<Func<object?,Stream,object>>(ref s_deserializeMethod!, () => // TODO-NULLABLE: Remove ! when nullable attributes are respected + LazyInitializer.EnsureInitialized(ref s_deserializeMethod, () => { MethodInfo binaryFormatterDeserialize = s_binaryFormatterType!.GetMethod("Deserialize", new Type[] { typeof(Stream) })!; diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeLibrary.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeLibrary.cs index 30d50fea7c..2062499057 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeLibrary.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeLibrary.cs @@ -235,7 +235,7 @@ namespace System.Runtime.InteropServices return IntPtr.Zero; } - if (!s_nativeDllResolveMap.TryGetValue(assembly, out DllImportResolver resolver)) + if (!s_nativeDllResolveMap.TryGetValue(assembly, out DllImportResolver? resolver)) { return IntPtr.Zero; } diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs b/src/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs index 4bc4ced0b9..230667b3a3 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs @@ -248,11 +248,7 @@ namespace System.Runtime.Loader foreach (WeakReference<AssemblyLoadContext> weakAlc in alcList) { - AssemblyLoadContext? alc = null; - - weakAlc.TryGetTarget(out alc); - - if (alc != null) + if (weakAlc.TryGetTarget(out AssemblyLoadContext? alc)) { yield return alc; } @@ -428,7 +424,7 @@ namespace System.Runtime.Loader { foreach (var alcAlive in s_allContexts) { - if (alcAlive.Value.TryGetTarget(out AssemblyLoadContext alc)) + if (alcAlive.Value.TryGetTarget(out AssemblyLoadContext? alc)) { alc.RaiseUnloadEvent(); } diff --git a/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs b/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs index 165ea4ee2f..81cd160bdc 100644 --- a/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs +++ b/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs @@ -1987,9 +1987,9 @@ namespace System.Text } else if (replacementsCount >= replacements.Length) { - Array.Resize(ref replacements!, replacements.Length * 3 / 2 + 4); // Grow by ~1.5x, but more in the begining // TODO-NULLABLE: Remove ! when nullable attributes are respected + Array.Resize(ref replacements, replacements.Length * 3 / 2 + 4); // Grow by ~1.5x, but more in the begining } - replacements![replacementsCount++] = indexInChunk; // TODO-NULLABLE: Remove ! when nullable attributes are respected + replacements[replacementsCount++] = indexInChunk; indexInChunk += oldValue.Length; count -= oldValue.Length; } diff --git a/src/System.Private.CoreLib/shared/System/Threading/ExecutionContext.cs b/src/System.Private.CoreLib/shared/System/Threading/ExecutionContext.cs index c1cae56594..8345e30d60 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/ExecutionContext.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/ExecutionContext.cs @@ -546,7 +546,7 @@ namespace System.Threading { int newNotificationIndex = newChangeNotifications.Length; Array.Resize(ref newChangeNotifications, newNotificationIndex + 1); - newChangeNotifications![newNotificationIndex] = local; // TODO-NULLABLE: Remove ! when nullable attributes are respected + newChangeNotifications[newNotificationIndex] = local; } } diff --git a/src/System.Private.CoreLib/shared/System/Threading/LazyInitializer.cs b/src/System.Private.CoreLib/shared/System/Threading/LazyInitializer.cs index 442e94234d..0ee21a2a70 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/LazyInitializer.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/LazyInitializer.cs @@ -48,7 +48,7 @@ namespace System.Threading /// if an object was not used and to then dispose of the object appropriately. /// </para> /// </remarks> - public static T EnsureInitialized<T>([AllowNull] ref T target) where T : class => + public static T EnsureInitialized<T>([NotNull] ref T? target) where T : class => Volatile.Read(ref target) ?? EnsureInitializedCore(ref target); /// <summary> @@ -57,7 +57,7 @@ namespace System.Threading /// <typeparam name="T">The reference type of the reference to be initialized.</typeparam> /// <param name="target">The variable that need to be initialized</param> /// <returns>The initialized variable</returns> - private static T EnsureInitializedCore<T>([AllowNull] ref T target) where T : class + private static T EnsureInitializedCore<T>([NotNull] ref T? target) where T : class { try { @@ -100,7 +100,7 @@ namespace System.Threading /// if an object was not used and to then dispose of the object appropriately. /// </para> /// </remarks> - public static T EnsureInitialized<T>([AllowNull] ref T target, Func<T> valueFactory) where T : class => + public static T EnsureInitialized<T>([NotNull] ref T? target, Func<T> valueFactory) where T : class => Volatile.Read(ref target) ?? EnsureInitializedCore(ref target, valueFactory); /// <summary> @@ -110,7 +110,7 @@ namespace System.Threading /// <param name="target">The variable that need to be initialized</param> /// <param name="valueFactory">The delegate that will be executed to initialize the target</param> /// <returns>The initialized variable</returns> - private static T EnsureInitializedCore<T>([AllowNull] ref T target, Func<T> valueFactory) where T : class + private static T EnsureInitializedCore<T>([NotNull] ref T? target, Func<T> valueFactory) where T : class { T value = valueFactory(); if (value == null) @@ -242,7 +242,7 @@ namespace System.Threading /// <paramref name="target"/>. If <paramref name="syncLock"/> is null, a new object will be instantiated.</param> /// <param name="valueFactory">The <see cref="T:System.Func{T}"/> invoked to initialize the reference.</param> /// <returns>The initialized value of type <typeparamref name="T"/>.</returns> - public static T EnsureInitialized<T>([AllowNull] ref T target, [NotNull] ref object? syncLock, Func<T> valueFactory) where T : class => + public static T EnsureInitialized<T>([NotNull] ref T? target, [NotNull] ref object? syncLock, Func<T> valueFactory) where T : class => Volatile.Read(ref target) ?? EnsureInitializedCore(ref target, ref syncLock, valueFactory); /// <summary> @@ -257,7 +257,7 @@ namespace System.Threading /// The <see cref="T:System.Func{T}"/> to invoke in order to produce the lazily-initialized value. /// </param> /// <returns>The initialized object.</returns> - private static T EnsureInitializedCore<T>([AllowNull] ref T target, [NotNull] ref object? syncLock, Func<T> valueFactory) where T : class + private static T EnsureInitializedCore<T>([NotNull] ref T? target, [NotNull] ref object? syncLock, Func<T> valueFactory) where T : class { // Lazily initialize the lock if necessary and then double check if initialization is still required. lock (EnsureLockInitialized(ref syncLock)) @@ -272,7 +272,7 @@ namespace System.Threading } } - return target; + return target!; // TODO-NULLABLE: Remove ! when nullable attributes are respected } /// <summary> diff --git a/src/System.Private.CoreLib/shared/System/Threading/Tasks/ConcurrentExclusiveSchedulerPair.cs b/src/System.Private.CoreLib/shared/System/Threading/Tasks/ConcurrentExclusiveSchedulerPair.cs index 7554097b1d..20a375135c 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Tasks/ConcurrentExclusiveSchedulerPair.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Tasks/ConcurrentExclusiveSchedulerPair.cs @@ -152,7 +152,7 @@ namespace System.Threading.Tasks private CompletionState EnsureCompletionStateInitialized() { // ValueLock not needed, but it's ok if it's held - return LazyInitializer.EnsureInitialized<CompletionState>(ref m_completionState!, () => new CompletionState()); // TODO-NULLABLE: Remove ! when nullable attributes are respected + return LazyInitializer.EnsureInitialized(ref m_completionState, () => new CompletionState()); } /// <summary>Gets whether completion has been requested.</summary> @@ -382,7 +382,7 @@ namespace System.Threading.Tasks for (int i = 0; i < m_maxItemsPerTask; i++) { // Get the next available exclusive task. If we can't find one, bail. - Task exclusiveTask; + Task? exclusiveTask; if (!m_exclusiveTaskScheduler.m_tasks.TryDequeue(out exclusiveTask)) break; // Execute the task. If the scheduler was previously faulted, @@ -430,7 +430,7 @@ namespace System.Threading.Tasks for (int i = 0; i < m_maxItemsPerTask; i++) { // Get the next available concurrent task. If we can't find one, bail. - Task concurrentTask; + Task? concurrentTask; if (!m_concurrentTaskScheduler.m_tasks.TryDequeue(out concurrentTask)) break; // Execute the task. If the scheduler was previously faulted, diff --git a/src/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs b/src/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs index 6e8dee7a1b..bf539a52de 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs @@ -194,7 +194,7 @@ namespace System.Threading.Tasks { Debug.Assert(task != null, "Null Task objects can't be added to the ActiveTasks collection"); - LazyInitializer.EnsureInitialized<Dictionary<int, Task>>(ref s_currentActiveTasks!, () => new Dictionary<int, Task>()); // TODO-NULLABLE: Remove ! when nullable attributes are respected + LazyInitializer.EnsureInitialized(ref s_currentActiveTasks, () => new Dictionary<int, Task>()); int taskId = task.Id; lock (s_currentActiveTasks) @@ -1343,7 +1343,7 @@ namespace System.Threading.Tasks /// <returns>The initialized contingent properties object.</returns> internal ContingentProperties EnsureContingentPropertiesInitialized() { - return LazyInitializer.EnsureInitialized<ContingentProperties>(ref m_contingentProperties!, () => new ContingentProperties())!; // TODO-NULLABLE: Remove ! when nullable attributes are respected + return LazyInitializer.EnsureInitialized(ref m_contingentProperties, () => new ContingentProperties()); } /// <summary> diff --git a/src/System.Private.CoreLib/shared/System/Threading/Thread.cs b/src/System.Private.CoreLib/shared/System/Threading/Thread.cs index 9707b03499..eeb2f413ce 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Thread.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Thread.cs @@ -355,7 +355,7 @@ namespace System.Threading Dictionary<string, LocalDataStoreSlot> nameToSlotMap = EnsureNameToSlotMap(); lock (nameToSlotMap) { - LocalDataStoreSlot slot; + LocalDataStoreSlot? slot; if (!nameToSlotMap.TryGetValue(name, out slot)) { slot = AllocateSlot(); diff --git a/src/System.Private.CoreLib/shared/System/TimeZoneInfo.Unix.cs b/src/System.Private.CoreLib/shared/System/TimeZoneInfo.Unix.cs index e56144f2f8..88c8893c3f 100644 --- a/src/System.Private.CoreLib/shared/System/TimeZoneInfo.Unix.cs +++ b/src/System.Private.CoreLib/shared/System/TimeZoneInfo.Unix.cs @@ -618,7 +618,7 @@ namespace System string? id; if (TryGetLocalTzFile(out rawData, out id)) { - TimeZoneInfo? result = GetTimeZoneFromTzData(rawData, id!); // TODO-NULLABLE: Remove ! when nullable attributes are respected + TimeZoneInfo? result = GetTimeZoneFromTzData(rawData, id); if (result != null) { return result; diff --git a/src/System.Private.CoreLib/shared/System/WeakReference.T.cs b/src/System.Private.CoreLib/shared/System/WeakReference.T.cs index 6121bdf12c..407c1bd34a 100644 --- a/src/System.Private.CoreLib/shared/System/WeakReference.T.cs +++ b/src/System.Private.CoreLib/shared/System/WeakReference.T.cs @@ -52,7 +52,7 @@ namespace System // DoSomething(ref.Target) // [MethodImplAttribute(MethodImplOptions.AggressiveInlining)] - public bool TryGetTarget([MaybeNull, NotNullWhen(true)] out T target) + public bool TryGetTarget([MaybeNullWhen(false), NotNullWhen(true)] out T target) { // Call the worker method that has more performant but less user friendly signature. T o = this.Target; diff --git a/src/System.Private.CoreLib/shared/System/WinRTFolderPaths.cs b/src/System.Private.CoreLib/shared/System/WinRTFolderPaths.cs index b0986dab09..ae065f0354 100644 --- a/src/System.Private.CoreLib/shared/System/WinRTFolderPaths.cs +++ b/src/System.Private.CoreLib/shared/System/WinRTFolderPaths.cs @@ -130,7 +130,7 @@ namespace System case SpecialFolder.System: return SystemDirectory; case SpecialFolder.Windows: - return Path.GetDirectoryName(SystemDirectory)!; // TODO-NULLABLE: Remove ! when nullable attributes are respected + return Path.GetDirectoryName(SystemDirectory)!; default: return string.Empty; } diff --git a/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs b/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs index 2c4d1a5a27..0a0590b45d 100644 --- a/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs +++ b/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs @@ -108,7 +108,7 @@ namespace Internal.Runtime.InteropServices { // Collection of all ALCs used for COM activation. In the event we want to support // unloadable COM server ALCs, this will need to be changed. - private static readonly Dictionary<string, AssemblyLoadContext> s_AssemblyLoadContexts = new Dictionary<string, AssemblyLoadContext>(StringComparer.InvariantCultureIgnoreCase); + private static readonly Dictionary<string, AssemblyLoadContext> s_assemblyLoadContexts = new Dictionary<string, AssemblyLoadContext>(StringComparer.InvariantCultureIgnoreCase); /// <summary> /// Entry point for unmanaged COM activation API from managed code @@ -370,14 +370,14 @@ $@"{nameof(UnregisterClassForTypeInternal)} arguments: private static AssemblyLoadContext GetALC(string assemblyPath) { - AssemblyLoadContext alc; + AssemblyLoadContext? alc; - lock (s_AssemblyLoadContexts) + lock (s_assemblyLoadContexts) { - if (!s_AssemblyLoadContexts.TryGetValue(assemblyPath, out alc)) + if (!s_assemblyLoadContexts.TryGetValue(assemblyPath, out alc)) { alc = new IsolatedComponentLoadContext(assemblyPath); - s_AssemblyLoadContexts.Add(assemblyPath, alc); + s_assemblyLoadContexts.Add(assemblyPath, alc); } } diff --git a/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs b/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs index e025413137..42a3838a46 100644 --- a/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs +++ b/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs @@ -15,14 +15,14 @@ namespace Internal.Runtime.InteropServices { public static class ComponentActivator { - private static readonly Dictionary<string, IsolatedComponentLoadContext> s_AssemblyLoadContexts; - private static readonly Dictionary<IntPtr, Delegate> s_Delegates = new Dictionary<IntPtr, Delegate>(); + private static readonly Dictionary<string, IsolatedComponentLoadContext> s_assemblyLoadContexts; + private static readonly Dictionary<IntPtr, Delegate> s_delegates = new Dictionary<IntPtr, Delegate>(); public delegate int ComponentEntryPoint(IntPtr args, int sizeBytes); static ComponentActivator() { - s_AssemblyLoadContexts = new Dictionary<string, IsolatedComponentLoadContext>(StringComparer.InvariantCulture); + s_assemblyLoadContexts = new Dictionary<string, IsolatedComponentLoadContext>(StringComparer.InvariantCulture); } private static string MarshalToString(IntPtr arg, string argName) @@ -91,10 +91,10 @@ namespace Internal.Runtime.InteropServices IntPtr functionPtr = Marshal.GetFunctionPointerForDelegate(d); - lock(s_Delegates) + lock(s_delegates) { // Keep a reference to the delegate to prevent it from being garbage collected - s_Delegates[functionPtr] = d; + s_delegates[functionPtr] = d; } Marshal.WriteIntPtr(functionHandle, functionPtr); @@ -126,14 +126,14 @@ namespace Internal.Runtime.InteropServices private static IsolatedComponentLoadContext GetIsolatedComponentLoadContext(string assemblyPath) { - IsolatedComponentLoadContext alc; + IsolatedComponentLoadContext? alc; - lock (s_AssemblyLoadContexts) + lock (s_assemblyLoadContexts) { - if (!s_AssemblyLoadContexts.TryGetValue(assemblyPath, out alc)) + if (!s_assemblyLoadContexts.TryGetValue(assemblyPath, out alc)) { alc = new IsolatedComponentLoadContext(assemblyPath); - s_AssemblyLoadContexts.Add(assemblyPath, alc); + s_assemblyLoadContexts.Add(assemblyPath, alc); } } diff --git a/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/WindowsRuntime/ActivationFactoryLoader.cs b/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/WindowsRuntime/ActivationFactoryLoader.cs index 5b691d608d..5c0a9433bb 100644 --- a/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/WindowsRuntime/ActivationFactoryLoader.cs +++ b/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/WindowsRuntime/ActivationFactoryLoader.cs @@ -16,18 +16,18 @@ namespace Internal.Runtime.InteropServices.WindowsRuntime // Since each of the assemblies that act as the "key" here are WinRT assemblies // we don't need to share this dictionary with the COM activation dictionary // since there will be no overlap. - private static Dictionary<string, AssemblyLoadContext> s_AssemblyLoadContexts = new Dictionary<string, AssemblyLoadContext>(StringComparer.InvariantCultureIgnoreCase); + private static readonly Dictionary<string, AssemblyLoadContext> s_assemblyLoadContexts = new Dictionary<string, AssemblyLoadContext>(StringComparer.InvariantCultureIgnoreCase); private static AssemblyLoadContext GetALC(string assemblyPath) { - AssemblyLoadContext alc; + AssemblyLoadContext? alc; - lock (s_AssemblyLoadContexts) + lock (s_assemblyLoadContexts) { - if (!s_AssemblyLoadContexts.TryGetValue(assemblyPath, out alc)) + if (!s_assemblyLoadContexts.TryGetValue(assemblyPath, out alc)) { alc = new IsolatedComponentLoadContext(assemblyPath); - s_AssemblyLoadContexts.Add(assemblyPath, alc); + s_assemblyLoadContexts.Add(assemblyPath, alc); } } diff --git a/src/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs index e17f430ebc..96a04fd502 100644 --- a/src/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs +++ b/src/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs @@ -390,7 +390,7 @@ namespace System for (int i = 0; i < attributes.Length; i++) { Type attrType = attributes[i].GetType(); - AttributeUsageAttribute usage; + AttributeUsageAttribute? usage; types.TryGetValue(attrType, out usage); if (usage == null) 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 91d933428b..6ec7e893ff 100644 --- a/src/System.Private.CoreLib/src/System/IO/FileLoadException.CoreCLR.cs +++ b/src/System.Private.CoreLib/src/System/IO/FileLoadException.CoreCLR.cs @@ -30,7 +30,7 @@ namespace System.IO else GetMessageForHR(hResult, JitHelpers.GetStringHandleOnStack(ref message)); - return string.Format(format!, fileName, message); // TODO-NULLABLE: Remove ! when nullable attributes are respected + return string.Format(format, fileName, message); } [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] diff --git a/src/System.Private.CoreLib/src/System/Reflection/Assembly.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Reflection/Assembly.CoreCLR.cs index eae84bf22a..463ea6c865 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Assembly.CoreCLR.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Assembly.CoreCLR.cs @@ -80,7 +80,7 @@ namespace System.Reflection { RuntimeAssembly? retAssembly = null; GetExecutingAssemblyNative(JitHelpers.GetStackCrawlMarkHandle(ref stackMark), JitHelpers.GetObjectHandleOnStack(ref retAssembly)); - return retAssembly!; // TODO-NULLABLE: Remove ! when nullable attributes are respected + return retAssembly; } // Get the assembly that the current code is running from. diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs index 042cf510bd..db4fb4a347 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs @@ -102,7 +102,7 @@ namespace System.Reflection.Emit internal void CheckTypeNameConflict(string strTypeName, Type? enclosingType) { - if (_typeBuilderDict.TryGetValue(strTypeName, out Type foundType) && + if (_typeBuilderDict.TryGetValue(strTypeName, out Type? foundType) && ReferenceEquals(foundType.DeclaringType, enclosingType)) { // Cannot have two types with the same name @@ -224,7 +224,7 @@ namespace System.Reflection.Emit } else { - if (_typeBuilderDict.TryGetValue(strTypeName, out Type foundType)) + if (_typeBuilderDict.TryGetValue(strTypeName, out Type? foundType)) { return foundType; } diff --git a/src/System.Private.CoreLib/src/System/RtType.cs b/src/System.Private.CoreLib/src/System/RtType.cs index 4d65e3d04d..4277b79b2e 100644 --- a/src/System.Private.CoreLib/src/System/RtType.cs +++ b/src/System.Private.CoreLib/src/System/RtType.cs @@ -128,15 +128,14 @@ namespace System _items = new T[_capacity]; _items[0] = _item; } - else - if (_capacity == _count) + else if (_capacity == _count) { int newCapacity = 2 * _capacity; Array.Resize(ref _items, newCapacity); _capacity = newCapacity; } - _items![_count] = item; // TODO-NULLABLE: Remove ! when nullable attributes are respected + _items![_count] = item; } _count++; } diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/EventRegistrationTokenTable.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/EventRegistrationTokenTable.cs index f9eb669b05..b2848c3929 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/EventRegistrationTokenTable.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/EventRegistrationTokenTable.cs @@ -152,7 +152,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // Remove the event handler from the table and // Get the delegate associated with an event registration token if it exists // If the event registration token is not registered, returns false - public bool RemoveEventHandler(EventRegistrationToken token, out T handler) + public bool RemoveEventHandler(EventRegistrationToken token, [NotNullWhen(true)] out T? handler) { lock (m_tokens) { @@ -196,7 +196,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // value. Therefore we need to make sure we really have the handler we want before taking the // fast path. EventRegistrationToken preferredToken = GetPreferredToken(handler); - T registeredHandler; + T? registeredHandler; if (m_tokens.TryGetValue(preferredToken, out registeredHandler)) { if (registeredHandler == handler) @@ -228,7 +228,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime private void RemoveEventHandlerNoLock(EventRegistrationToken token) { - T handler; + T? handler; if (m_tokens.TryGetValue(token, out handler)) { m_tokens.Remove(token); diff --git a/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs b/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs index ad9f585aa5..c2f1bf3ae5 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs @@ -144,7 +144,7 @@ namespace System.Runtime.Loader 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)) + if (_assemblyPaths.TryGetValue(assemblyName.Name, out string? assemblyPath)) { // Only returnd the assembly if it exists on disk - this is to make the behavior of the API // consistent. Resource and native resolutions will only return existing files |