diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MountPoints.FormatInfo.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MountPoints.FormatInfo.cs index 4240bd4853ab70..ee5e4272295286 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MountPoints.FormatInfo.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MountPoints.FormatInfo.cs @@ -163,14 +163,12 @@ private static extern unsafe int GetFormatInfoForMountPoint( internal static int GetFormatInfoForMountPoint(string name, out string format) { - DriveType temp; - return GetFormatInfoForMountPoint(name, out format, out temp); + return GetFormatInfoForMountPoint(name, out format, out _); } internal static int GetFormatInfoForMountPoint(string name, out DriveType type) { - string temp; - return GetFormatInfoForMountPoint(name, out temp, out type); + return GetFormatInfoForMountPoint(name, out _, out type); } private static int GetFormatInfoForMountPoint(string name, out string format, out DriveType type) @@ -184,8 +182,8 @@ private static int GetFormatInfoForMountPoint(string name, out string format, ou { // Check if we have a numeric answer or string format = numericFormat != -1 ? - Enum.GetName(typeof(UnixFileSystemTypes), numericFormat) : - Marshal.PtrToStringAnsi((IntPtr)formatBuffer); + Enum.GetName(typeof(UnixFileSystemTypes), numericFormat) ?? string.Empty : + Marshal.PtrToStringAnsi((IntPtr)formatBuffer)!; type = GetDriveType(format); } else diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.SetVolumeLabel.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.SetVolumeLabel.cs index e28a3e659a1e5f..d23c7f33b8a0d5 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.SetVolumeLabel.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.SetVolumeLabel.cs @@ -9,6 +9,6 @@ internal partial class Interop internal partial class Kernel32 { [DllImport(Libraries.Kernel32, EntryPoint = "SetVolumeLabelW", CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)] - internal static extern bool SetVolumeLabel(string driveLetter, string volumeName); + internal static extern bool SetVolumeLabel(string driveLetter, string? volumeName); } } diff --git a/src/libraries/System.IO.FileSystem.DriveInfo/ref/System.IO.FileSystem.DriveInfo.cs b/src/libraries/System.IO.FileSystem.DriveInfo/ref/System.IO.FileSystem.DriveInfo.cs index d2c102e6737cbe..f76bd6cc7f89b6 100644 --- a/src/libraries/System.IO.FileSystem.DriveInfo/ref/System.IO.FileSystem.DriveInfo.cs +++ b/src/libraries/System.IO.FileSystem.DriveInfo/ref/System.IO.FileSystem.DriveInfo.cs @@ -18,6 +18,7 @@ public DriveInfo(string driveName) { } public System.IO.DirectoryInfo RootDirectory { get { throw null; } } public long TotalFreeSpace { get { throw null; } } public long TotalSize { get { throw null; } } + [System.Diagnostics.CodeAnalysis.AllowNull] public string VolumeLabel { get { throw null; } set { } } public static System.IO.DriveInfo[] GetDrives() { throw null; } void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } @@ -27,8 +28,8 @@ public partial class DriveNotFoundException : System.IO.IOException { public DriveNotFoundException() { } protected DriveNotFoundException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } - public DriveNotFoundException(string message) { } - public DriveNotFoundException(string message, System.Exception innerException) { } + public DriveNotFoundException(string? message) { } + public DriveNotFoundException(string? message, System.Exception? innerException) { } } public enum DriveType { diff --git a/src/libraries/System.IO.FileSystem.DriveInfo/ref/System.IO.FileSystem.DriveInfo.csproj b/src/libraries/System.IO.FileSystem.DriveInfo/ref/System.IO.FileSystem.DriveInfo.csproj index 97fd59eef52590..2027e8706f5419 100644 --- a/src/libraries/System.IO.FileSystem.DriveInfo/ref/System.IO.FileSystem.DriveInfo.csproj +++ b/src/libraries/System.IO.FileSystem.DriveInfo/ref/System.IO.FileSystem.DriveInfo.csproj @@ -1,5 +1,6 @@ + enable netcoreapp-Debug;netcoreapp-Release diff --git a/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj b/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj index 2d0b6ff1b39b20..cd18c3fb3a7fc4 100644 --- a/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj +++ b/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj @@ -3,6 +3,7 @@ System.IO.FileSystem.DriveInfo System.IO.FileSystem.DriveInfo true + enable netcoreapp-Unix-Debug;netcoreapp-Unix-Release;netcoreapp-Windows_NT-Debug;netcoreapp-Windows_NT-Release diff --git a/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Unix.cs b/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Unix.cs index 1322cceb27587e..19aff6860ca62a 100644 --- a/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Unix.cs +++ b/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Unix.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Security; namespace System.IO @@ -104,6 +105,7 @@ public long TotalSize } } + [AllowNull] public string VolumeLabel { get diff --git a/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Windows.cs b/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Windows.cs index 412959a55b3012..ef454de2698cf6 100644 --- a/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Windows.cs +++ b/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Windows.cs @@ -4,6 +4,7 @@ using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using System.Text; @@ -121,6 +122,7 @@ public static DriveInfo[] GetDrives() } // Null is a valid volume label. + [AllowNull] public unsafe string VolumeLabel { get diff --git a/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveNotFoundException.cs b/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveNotFoundException.cs index 9cf3af8dc3e5d4..c347dbbb169d4f 100644 --- a/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveNotFoundException.cs +++ b/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveNotFoundException.cs @@ -17,13 +17,13 @@ public DriveNotFoundException() HResult = HResults.COR_E_DIRECTORYNOTFOUND; } - public DriveNotFoundException(string message) + public DriveNotFoundException(string? message) : base(message) { HResult = HResults.COR_E_DIRECTORYNOTFOUND; } - public DriveNotFoundException(string message, Exception innerException) + public DriveNotFoundException(string? message, Exception? innerException) : base(message, innerException) { HResult = HResults.COR_E_DIRECTORYNOTFOUND;