From 66e021da77116a5ec22c9dfad63cce58ed8f713a Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 22 Aug 2021 17:24:04 +0800 Subject: [PATCH 01/10] Enable nullable in project file. --- .../src/System.Windows.Extensions.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/System.Windows.Extensions/src/System.Windows.Extensions.csproj b/src/libraries/System.Windows.Extensions/src/System.Windows.Extensions.csproj index f2d4cc54d1012..d875cae47a5cd 100644 --- a/src/libraries/System.Windows.Extensions/src/System.Windows.Extensions.csproj +++ b/src/libraries/System.Windows.Extensions/src/System.Windows.Extensions.csproj @@ -2,6 +2,7 @@ true $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent);netcoreapp3.1-windows;netcoreapp3.1 + enable true Provides miscellaneous Windows-specific types From 00fcf077e287b83dc6a51914819802645dc525a9 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 22 Aug 2021 18:28:52 +0800 Subject: [PATCH 02/10] Annotate SoundPlayer --- .../Windows/WinMm/Interop.PlaySound.cs | 2 +- .../Windows/WinMm/Interop.mmioDescend.cs | 2 +- .../src/System/Media/SoundPlayer.cs | 47 ++++++++++--------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/libraries/Common/src/Interop/Windows/WinMm/Interop.PlaySound.cs b/src/libraries/Common/src/Interop/Windows/WinMm/Interop.PlaySound.cs index 771fa9d1b2fd2..f45bf172e2f62 100644 --- a/src/libraries/Common/src/Interop/Windows/WinMm/Interop.PlaySound.cs +++ b/src/libraries/Common/src/Interop/Windows/WinMm/Interop.PlaySound.cs @@ -21,6 +21,6 @@ internal static partial class WinMM internal static extern bool PlaySound(string soundName, IntPtr hmod, int soundFlags); [DllImport(Libraries.WinMM, ExactSpelling = true, EntryPoint = "PlaySoundW")] - internal static extern bool PlaySound(byte[] soundName, IntPtr hmod, int soundFlags); + internal static extern bool PlaySound(byte[]? soundName, IntPtr hmod, int soundFlags); } } diff --git a/src/libraries/Common/src/Interop/Windows/WinMm/Interop.mmioDescend.cs b/src/libraries/Common/src/Interop/Windows/WinMm/Interop.mmioDescend.cs index ede50147bd43a..4ffe7eb47d4af 100644 --- a/src/libraries/Common/src/Interop/Windows/WinMm/Interop.mmioDescend.cs +++ b/src/libraries/Common/src/Interop/Windows/WinMm/Interop.mmioDescend.cs @@ -13,7 +13,7 @@ internal static partial class WinMM [DllImport(Libraries.WinMM)] internal static extern int mmioDescend(IntPtr hMIO, [MarshalAs(UnmanagedType.LPStruct)] MMCKINFO lpck, - [MarshalAs(UnmanagedType.LPStruct)] MMCKINFO lcpkParent, + [MarshalAs(UnmanagedType.LPStruct)] MMCKINFO? lcpkParent, int flags); } } diff --git a/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs b/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs index 94d8b13873d80..194cfd49f0f7b 100644 --- a/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs +++ b/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs @@ -18,7 +18,7 @@ public class SoundPlayer : Component, ISerializable private const int BlockSize = 1024; private const int DefaultLoadTimeout = 10000; // 10 secs - private Uri _uri; + private Uri? _uri; private string _soundLocation = string.Empty; private int _loadTimeout = DefaultLoadTimeout; @@ -28,16 +28,16 @@ public class SoundPlayer : Component, ISerializable // the worker copyTask // we start the worker copyTask ONLY from entry points in the SoundPlayer API // we also set the tread to null only from the entry points in the SoundPlayer API - private Task _copyTask; - private CancellationTokenSource _copyTaskCancellation; + private Task? _copyTask; + private CancellationTokenSource? _copyTaskCancellation; // local buffer information private int _currentPos; - private Stream _stream; - private Exception _lastLoadException; + private Stream? _stream; + private Exception? _lastLoadException; private bool _doesLoadAppearSynchronous; - private byte[] _streamData; - private AsyncOperation _asyncOperation; + private byte[]? _streamData; + private AsyncOperation? _asyncOperation; private readonly SendOrPostCallback _loadAsyncOperationCompleted; // event @@ -50,7 +50,7 @@ public SoundPlayer() _loadAsyncOperationCompleted = new SendOrPostCallback(LoadAsyncOperationCompleted); } - public SoundPlayer(string soundLocation) : this() + public SoundPlayer(string? soundLocation) : this() { SetupSoundLocation(soundLocation ?? string.Empty); } @@ -99,7 +99,7 @@ public string SoundLocation } } - public Stream Stream + public Stream? Stream { get { @@ -126,7 +126,7 @@ public Stream Stream public bool IsLoadCompleted { get; private set; } - public object Tag { get; set; } + public object? Tag { get; set; } public void LoadAsync() { @@ -161,9 +161,9 @@ public void LoadAsync() LoadStream(false); } - private void LoadAsyncOperationCompleted(object arg) + private void LoadAsyncOperationCompleted(object? arg) { - OnLoadCompleted((AsyncCompletedEventArgs)arg); + OnLoadCompleted((AsyncCompletedEventArgs)arg!); } // called for loading a stream synchronously @@ -227,6 +227,7 @@ private void LoadAndPlay(int flags) else { LoadSync(); + Debug.Assert(_streamData != null); ValidateSoundData(_streamData); Interop.WinMM.PlaySound(_streamData, IntPtr.Zero, Interop.WinMM.SND_MEMORY | Interop.WinMM.SND_NODEFAULT | flags); } @@ -271,6 +272,7 @@ private void LoadSync() _stream = webResponse.GetResponseStream(); } + Debug.Assert(_stream != null); if (_stream.CanSeek) { // if we can get data synchronously, then get it @@ -304,6 +306,7 @@ private void LoadSync() private void LoadStream(bool loadSync) { + Debug.Assert(_stream != null); if (loadSync && _stream.CanSeek) { int streamLen = (int)_stream.Length; @@ -339,9 +342,9 @@ public void PlayLooping() LoadAndPlay(Interop.WinMM.SND_LOOP | Interop.WinMM.SND_ASYNC); } - private static Uri ResolveUri(string partialUri) + private static Uri? ResolveUri(string partialUri) { - Uri result = null; + Uri? result = null; try { result = new Uri(partialUri); @@ -399,7 +402,7 @@ private void SetupSoundLocation(string soundLocation) } } - private void SetupStream(Stream stream) + private void SetupStream(Stream? stream) { if (_copyTask != null) { @@ -420,7 +423,7 @@ private void SetupStream(Stream stream) public void Stop() { - Interop.WinMM.PlaySound((byte[])null, IntPtr.Zero, Interop.WinMM.SND_PURGE); + Interop.WinMM.PlaySound((byte[]?)null, IntPtr.Zero, Interop.WinMM.SND_PURGE); } public event AsyncCompletedEventHandler LoadCompleted @@ -461,17 +464,17 @@ public event EventHandler StreamChanged protected virtual void OnLoadCompleted(AsyncCompletedEventArgs e) { - ((AsyncCompletedEventHandler)Events[s_eventLoadCompleted])?.Invoke(this, e); + ((AsyncCompletedEventHandler?)Events[s_eventLoadCompleted])?.Invoke(this, e); } protected virtual void OnSoundLocationChanged(EventArgs e) { - ((EventHandler)Events[s_eventSoundLocationChanged])?.Invoke(this, e); + ((EventHandler?)Events[s_eventSoundLocationChanged])?.Invoke(this, e); } protected virtual void OnStreamChanged(EventArgs e) { - ((EventHandler)Events[s_eventStreamChanged])?.Invoke(this, e); + ((EventHandler?)Events[s_eventStreamChanged])?.Invoke(this, e); } private async Task CopyStreamAsync(CancellationToken cancellationToken) @@ -484,7 +487,7 @@ private async Task CopyStreamAsync(CancellationToken cancellationToken) #pragma warning disable SYSLIB0014 // WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead. WebRequest webRequest = WebRequest.Create(_uri); #pragma warning restore SYSLIB0014 - using (cancellationToken.Register(r => ((WebRequest)r).Abort(), webRequest)) + using (cancellationToken.Register(r => ((WebRequest)r!).Abort(), webRequest)) { WebResponse webResponse = await webRequest.GetResponseAsync().ConfigureAwait(false); _stream = webResponse.GetResponseStream(); @@ -493,6 +496,7 @@ private async Task CopyStreamAsync(CancellationToken cancellationToken) _streamData = new byte[BlockSize]; + Debug.Assert(_stream != null); int readBytes = await _stream.ReadAsync(_streamData.AsMemory(_currentPos, BlockSize), cancellationToken).ConfigureAwait(false); int totalBytes = readBytes; @@ -525,6 +529,7 @@ private async Task CopyStreamAsync(CancellationToken cancellationToken) AsyncCompletedEventArgs ea = _lastLoadException is OperationCanceledException ? new AsyncCompletedEventArgs(null, cancelled: true, null) : new AsyncCompletedEventArgs(_lastLoadException, cancelled: false, null); + Debug.Assert(_asyncOperation != null); _asyncOperation.PostOperationCompleted(_loadAsyncOperationCompleted, ea); } } @@ -539,7 +544,7 @@ private unsafe void ValidateSoundFile(string fileName) try { - Interop.WinMM.WAVEFORMATEX waveFormat = null; + Interop.WinMM.WAVEFORMATEX? waveFormat = null; var ckRIFF = new Interop.WinMM.MMCKINFO() { fccType = mmioFOURCC('W', 'A', 'V', 'E') From 52898fd0203b873cc384f5b2ae09d1ff4940c128 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 22 Aug 2021 18:38:05 +0800 Subject: [PATCH 03/10] Annotate remaining types --- .../Interop/Windows/Crypt32/Interop.CertOpenStore.cs | 2 +- .../Windows/CryptUI/Interop.CryptUIDlgCertificate.cs | 6 +++--- .../src/System/Media/SystemSounds.cs | 10 +++++----- .../src/System/Xaml/Permissions/XamlAccessLevel.cs | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertOpenStore.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertOpenStore.cs index a0f85dc39f765..c6667d5162252 100644 --- a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertOpenStore.cs +++ b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertOpenStore.cs @@ -14,6 +14,6 @@ internal static partial class Crypt32 internal const uint CERT_STORE_PROV_MEMORY = 2; [DllImport(Interop.Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)] - internal static extern SafeCertStoreHandle CertOpenStore(IntPtr lpszStoreProvider, uint dwMsgAndCertEncodingType, IntPtr hCryptProv, uint dwFlags, string pvPara); + internal static extern SafeCertStoreHandle CertOpenStore(IntPtr lpszStoreProvider, uint dwMsgAndCertEncodingType, IntPtr hCryptProv, uint dwFlags, string? pvPara); } } diff --git a/src/libraries/Common/src/Interop/Windows/CryptUI/Interop.CryptUIDlgCertificate.cs b/src/libraries/Common/src/Interop/Windows/CryptUI/Interop.CryptUIDlgCertificate.cs index 976a6396118e1..75d2af44a0bf7 100644 --- a/src/libraries/Common/src/Interop/Windows/CryptUI/Interop.CryptUIDlgCertificate.cs +++ b/src/libraries/Common/src/Interop/Windows/CryptUI/Interop.CryptUIDlgCertificate.cs @@ -15,7 +15,7 @@ internal sealed class CRYPTUI_VIEWCERTIFICATE_STRUCTW internal uint dwSize; internal IntPtr hwndParent; internal uint dwFlags; - internal string szTitle; + internal string? szTitle; internal IntPtr pCertContext; internal IntPtr rgszPurposes; internal uint cPurposes; @@ -38,9 +38,9 @@ internal sealed class CRYPTUI_SELECTCERTIFICATE_STRUCTW internal uint dwSize; internal IntPtr hwndParent; internal uint dwFlags; - internal string szTitle; + internal string? szTitle; internal uint dwDontUseColumn; - internal string szDisplayString; + internal string? szDisplayString; internal IntPtr pFilterCallback; internal IntPtr pDisplayCallback; internal IntPtr pvCallbackData; diff --git a/src/libraries/System.Windows.Extensions/src/System/Media/SystemSounds.cs b/src/libraries/System.Windows.Extensions/src/System/Media/SystemSounds.cs index 145b53cd8c106..b6bffe257a733 100644 --- a/src/libraries/System.Windows.Extensions/src/System/Media/SystemSounds.cs +++ b/src/libraries/System.Windows.Extensions/src/System/Media/SystemSounds.cs @@ -5,11 +5,11 @@ namespace System.Media { public static class SystemSounds { - private static volatile SystemSound s_asterisk; - private static volatile SystemSound s_beep; - private static volatile SystemSound s_exclamation; - private static volatile SystemSound s_hand; - private static volatile SystemSound s_question; + private static volatile SystemSound? s_asterisk; + private static volatile SystemSound? s_beep; + private static volatile SystemSound? s_exclamation; + private static volatile SystemSound? s_hand; + private static volatile SystemSound? s_question; public static SystemSound Asterisk { diff --git a/src/libraries/System.Windows.Extensions/src/System/Xaml/Permissions/XamlAccessLevel.cs b/src/libraries/System.Windows.Extensions/src/System/Xaml/Permissions/XamlAccessLevel.cs index 123543a802443..3c4d510fd3a17 100644 --- a/src/libraries/System.Windows.Extensions/src/System/Xaml/Permissions/XamlAccessLevel.cs +++ b/src/libraries/System.Windows.Extensions/src/System/Xaml/Permissions/XamlAccessLevel.cs @@ -8,7 +8,7 @@ namespace System.Xaml.Permissions { public class XamlAccessLevel { - private XamlAccessLevel(string assemblyName, string typeName) + private XamlAccessLevel(string assemblyName, string? typeName) { AssemblyNameString = assemblyName; PrivateAccessToTypeName = typeName; @@ -16,7 +16,7 @@ private XamlAccessLevel(string assemblyName, string typeName) public static XamlAccessLevel AssemblyAccessTo(Assembly assembly) { - return new XamlAccessLevel(assembly.FullName, null); + return new XamlAccessLevel(assembly.FullName!, null); } public static XamlAccessLevel AssemblyAccessTo(AssemblyName assemblyName) @@ -26,7 +26,7 @@ public static XamlAccessLevel AssemblyAccessTo(AssemblyName assemblyName) public static XamlAccessLevel PrivateAccessTo(Type type) { - return new XamlAccessLevel(type.Assembly.FullName, type.FullName); + return new XamlAccessLevel(type.Assembly.FullName!, type.FullName); } public static XamlAccessLevel PrivateAccessTo(string assemblyQualifiedTypeName) @@ -43,7 +43,7 @@ public AssemblyName AssemblyAccessToAssemblyName get { return new AssemblyName(AssemblyNameString); } } - public string PrivateAccessToTypeName { get; private set; } + public string? PrivateAccessToTypeName { get; private set; } internal string AssemblyNameString { get; private set; } } From fabeb332294dfc21f4a46c0c0bb8ad918498dfda Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 22 Aug 2021 18:52:22 +0800 Subject: [PATCH 04/10] Update ref source --- .../ref/System.Windows.Extensions.cs | 12 ++++++------ .../ref/System.Windows.Extensions.csproj | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.cs b/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.cs index 057fbfc5ed318..43680ecaa92b2 100644 --- a/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.cs +++ b/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.cs @@ -16,11 +16,11 @@ public SoundPlayer(string soundLocation) { } public bool IsLoadCompleted { get { throw null; } } public int LoadTimeout { get { throw null; } set { } } public string SoundLocation { get { throw null; } set { } } - public System.IO.Stream Stream { get { throw null; } set { } } - public object Tag { get { throw null; } set { } } - public event System.ComponentModel.AsyncCompletedEventHandler LoadCompleted { add { } remove { } } - public event System.EventHandler SoundLocationChanged { add { } remove { } } - public event System.EventHandler StreamChanged { add { } remove { } } + public System.IO.Stream? Stream { get { throw null; } set { } } + public object? Tag { get { throw null; } set { } } + public event System.ComponentModel.AsyncCompletedEventHandler? LoadCompleted { add { } remove { } } + public event System.EventHandler? SoundLocationChanged { add { } remove { } } + public event System.EventHandler? StreamChanged { add { } remove { } } public void Load() { } public void LoadAsync() { } protected virtual void OnLoadCompleted(System.ComponentModel.AsyncCompletedEventArgs e) { } @@ -68,7 +68,7 @@ public partial class XamlAccessLevel { internal XamlAccessLevel() { } public System.Reflection.AssemblyName AssemblyAccessToAssemblyName { get { throw null; } } - public string PrivateAccessToTypeName { get { throw null; } } + public string? PrivateAccessToTypeName { get { throw null; } } public static System.Xaml.Permissions.XamlAccessLevel AssemblyAccessTo(System.Reflection.Assembly assembly) { throw null; } public static System.Xaml.Permissions.XamlAccessLevel AssemblyAccessTo(System.Reflection.AssemblyName assemblyName) { throw null; } public static System.Xaml.Permissions.XamlAccessLevel PrivateAccessTo(string assemblyQualifiedTypeName) { throw null; } diff --git a/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.csproj b/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.csproj index 080d2f34b074a..23a610ae0ef0c 100644 --- a/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.csproj +++ b/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.csproj @@ -1,6 +1,7 @@ $(NetCoreAppCurrent);netcoreapp3.1 + enable From de1565826e20a2d48dd231a76b0554cd02448e08 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 22 Aug 2021 18:59:13 +0800 Subject: [PATCH 05/10] Events should be nullable --- .../src/System/Media/SoundPlayer.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs b/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs index 194cfd49f0f7b..75a95ba00155e 100644 --- a/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs +++ b/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs @@ -426,7 +426,7 @@ public void Stop() Interop.WinMM.PlaySound((byte[]?)null, IntPtr.Zero, Interop.WinMM.SND_PURGE); } - public event AsyncCompletedEventHandler LoadCompleted + public event AsyncCompletedEventHandler? LoadCompleted { add { @@ -438,7 +438,7 @@ public event AsyncCompletedEventHandler LoadCompleted } } - public event EventHandler SoundLocationChanged + public event EventHandler? SoundLocationChanged { add { @@ -450,7 +450,7 @@ public event EventHandler SoundLocationChanged } } - public event EventHandler StreamChanged + public event EventHandler? StreamChanged { add { From 4e1f870603c966e249265835d7112146dc0b628f Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 22 Aug 2021 22:31:30 +0800 Subject: [PATCH 06/10] Fix assertion for NRE --- .../src/System/Media/SoundPlayer.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs b/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs index 75a95ba00155e..a30b495dd8f15 100644 --- a/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs +++ b/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs @@ -272,8 +272,9 @@ private void LoadSync() _stream = webResponse.GetResponseStream(); } - Debug.Assert(_stream != null); - if (_stream.CanSeek) + // DO NOT assert - NRE is expected for null stream + // See SoundPlayerTests.Load_NullStream_ThrowsNullReferenceException + if (_stream!.CanSeek) { // if we can get data synchronously, then get it LoadStream(true); From 22d98fd3eadc0ad4bd3c3d7d4b3eb10df92da38f Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Wed, 25 Aug 2021 20:31:56 +0800 Subject: [PATCH 07/10] Update nullability of SoundLocation. --- .../System.Windows.Extensions/ref/System.Windows.Extensions.cs | 3 ++- .../System.Windows.Extensions/src/System/Media/SoundPlayer.cs | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.cs b/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.cs index 43680ecaa92b2..57b489a91e334 100644 --- a/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.cs +++ b/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.cs @@ -12,9 +12,10 @@ public partial class SoundPlayer : System.ComponentModel.Component, System.Runti public SoundPlayer() { } public SoundPlayer(System.IO.Stream stream) { } protected SoundPlayer(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext context) { } - public SoundPlayer(string soundLocation) { } + public SoundPlayer(string? soundLocation) { } public bool IsLoadCompleted { get { throw null; } } public int LoadTimeout { get { throw null; } set { } } + [System.Diagnostics.CodeAnalysis.AllowNullAttribute] public string SoundLocation { get { throw null; } set { } } public System.IO.Stream? Stream { get { throw null; } set { } } public object? Tag { get { throw null; } set { } } diff --git a/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs b/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs index a30b495dd8f15..4b46b4bed3608 100644 --- a/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs +++ b/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs @@ -3,6 +3,7 @@ using System.ComponentModel; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Net; using System.Runtime.InteropServices; @@ -79,6 +80,7 @@ public int LoadTimeout } } + [AllowNull] public string SoundLocation { get => _soundLocation; From 599cdce6c57ddb43f230a3a54b2b47031782daa9 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Wed, 8 Sep 2021 00:49:05 +0800 Subject: [PATCH 08/10] Adjust nullability of SoundLocation and Stream. --- .../ref/System.Windows.Extensions.cs | 5 ++--- .../src/System/Media/SoundPlayer.cs | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.cs b/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.cs index 57b489a91e334..ae318159d26e2 100644 --- a/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.cs +++ b/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.cs @@ -10,12 +10,11 @@ namespace System.Media public partial class SoundPlayer : System.ComponentModel.Component, System.Runtime.Serialization.ISerializable { public SoundPlayer() { } - public SoundPlayer(System.IO.Stream stream) { } + public SoundPlayer(System.IO.Stream? stream) { } protected SoundPlayer(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext context) { } - public SoundPlayer(string? soundLocation) { } + public SoundPlayer(string soundLocation) { } public bool IsLoadCompleted { get { throw null; } } public int LoadTimeout { get { throw null; } set { } } - [System.Diagnostics.CodeAnalysis.AllowNullAttribute] public string SoundLocation { get { throw null; } set { } } public System.IO.Stream? Stream { get { throw null; } set { } } public object? Tag { get { throw null; } set { } } diff --git a/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs b/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs index 4b46b4bed3608..4ce1949dd263a 100644 --- a/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs +++ b/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs @@ -51,12 +51,12 @@ public SoundPlayer() _loadAsyncOperationCompleted = new SendOrPostCallback(LoadAsyncOperationCompleted); } - public SoundPlayer(string? soundLocation) : this() + public SoundPlayer(string soundLocation) : this() { SetupSoundLocation(soundLocation ?? string.Empty); } - public SoundPlayer(Stream stream) : this() + public SoundPlayer(Stream? stream) : this() { _stream = stream; } @@ -80,7 +80,6 @@ public int LoadTimeout } } - [AllowNull] public string SoundLocation { get => _soundLocation; From f8103126db318dd9602b0b0e50574efa5e97faae Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Wed, 8 Sep 2021 00:55:01 +0800 Subject: [PATCH 09/10] Title and message should be nullable --- .../ref/System.Windows.Extensions.cs | 4 ++-- .../Cryptography/X509Certificates/X509Certificate2UI.cs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.cs b/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.cs index ae318159d26e2..c1f732f2baad4 100644 --- a/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.cs +++ b/src/libraries/System.Windows.Extensions/ref/System.Windows.Extensions.cs @@ -53,8 +53,8 @@ public sealed partial class X509Certificate2UI public X509Certificate2UI() { } public static void DisplayCertificate(System.Security.Cryptography.X509Certificates.X509Certificate2 certificate) { } public static void DisplayCertificate(System.Security.Cryptography.X509Certificates.X509Certificate2 certificate, System.IntPtr hwndParent) { } - public static System.Security.Cryptography.X509Certificates.X509Certificate2Collection SelectFromCollection(System.Security.Cryptography.X509Certificates.X509Certificate2Collection certificates, string title, string message, System.Security.Cryptography.X509Certificates.X509SelectionFlag selectionFlag) { throw null; } - public static System.Security.Cryptography.X509Certificates.X509Certificate2Collection SelectFromCollection(System.Security.Cryptography.X509Certificates.X509Certificate2Collection certificates, string title, string message, System.Security.Cryptography.X509Certificates.X509SelectionFlag selectionFlag, System.IntPtr hwndParent) { throw null; } + public static System.Security.Cryptography.X509Certificates.X509Certificate2Collection SelectFromCollection(System.Security.Cryptography.X509Certificates.X509Certificate2Collection certificates, string? title, string? message, System.Security.Cryptography.X509Certificates.X509SelectionFlag selectionFlag) { throw null; } + public static System.Security.Cryptography.X509Certificates.X509Certificate2Collection SelectFromCollection(System.Security.Cryptography.X509Certificates.X509Certificate2Collection certificates, string? title, string? message, System.Security.Cryptography.X509Certificates.X509SelectionFlag selectionFlag, System.IntPtr hwndParent) { throw null; } } public enum X509SelectionFlag { diff --git a/src/libraries/System.Windows.Extensions/src/System/Security/Cryptography/X509Certificates/X509Certificate2UI.cs b/src/libraries/System.Windows.Extensions/src/System/Security/Cryptography/X509Certificates/X509Certificate2UI.cs index 43afbdd9763cc..d0c02eaf64baf 100644 --- a/src/libraries/System.Windows.Extensions/src/System/Security/Cryptography/X509Certificates/X509Certificate2UI.cs +++ b/src/libraries/System.Windows.Extensions/src/System/Security/Cryptography/X509Certificates/X509Certificate2UI.cs @@ -30,12 +30,12 @@ public static void DisplayCertificate(X509Certificate2 certificate, IntPtr hwndP DisplayX509Certificate(certificate, hwndParent); } - public static X509Certificate2Collection SelectFromCollection(X509Certificate2Collection certificates, string title, string message, X509SelectionFlag selectionFlag) + public static X509Certificate2Collection SelectFromCollection(X509Certificate2Collection certificates, string? title, string? message, X509SelectionFlag selectionFlag) { return SelectFromCollectionHelper(certificates, title, message, selectionFlag, IntPtr.Zero); } - public static X509Certificate2Collection SelectFromCollection(X509Certificate2Collection certificates, string title, string message, X509SelectionFlag selectionFlag, IntPtr hwndParent) + public static X509Certificate2Collection SelectFromCollection(X509Certificate2Collection certificates, string? title, string? message, X509SelectionFlag selectionFlag, IntPtr hwndParent) { return SelectFromCollectionHelper(certificates, title, message, selectionFlag, hwndParent); } @@ -81,7 +81,7 @@ private static void DisplayX509Certificate(X509Certificate2 certificate, IntPtr } } - private static X509Certificate2Collection SelectFromCollectionHelper(X509Certificate2Collection certificates, string title, string message, X509SelectionFlag selectionFlag, IntPtr hwndParent) + private static X509Certificate2Collection SelectFromCollectionHelper(X509Certificate2Collection certificates, string? title, string? message, X509SelectionFlag selectionFlag, IntPtr hwndParent) { if (certificates == null) throw new ArgumentNullException(nameof(certificates)); @@ -95,7 +95,7 @@ private static X509Certificate2Collection SelectFromCollectionHelper(X509Certifi } } - private static unsafe SafeCertStoreHandle SelectFromStore(SafeCertStoreHandle safeSourceStoreHandle, string title, string message, X509SelectionFlag selectionFlags, IntPtr hwndParent) + private static unsafe SafeCertStoreHandle SelectFromStore(SafeCertStoreHandle safeSourceStoreHandle, string? title, string? message, X509SelectionFlag selectionFlags, IntPtr hwndParent) { int dwErrorCode = ERROR_SUCCESS; From 689255c34fd70f77581604efcb363861bd5d8655 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 23 Sep 2021 17:26:52 +0800 Subject: [PATCH 10/10] Fix new NRT issue --- .../System.Windows.Extensions/src/System/Media/SoundPlayer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs b/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs index f6fc0fade9436..ec2077ec31e9c 100644 --- a/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs +++ b/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs @@ -481,7 +481,7 @@ protected virtual void OnStreamChanged(EventArgs e) private async Task CopyStreamAsync(CancellationToken cancellationToken) { - Exception exception = null; + Exception? exception = null; try { // setup the http stream