From 0b0ed7296f55ef3d9e17e5b693b822256c0c5e90 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Tue, 22 Jun 2021 13:21:55 +0200 Subject: [PATCH 01/25] Use property to indicate NetCoreApp min version --- Directory.Build.props | 1 + .../src/Microsoft.Extensions.Logging.Console.csproj | 2 +- .../src/Microsoft.Extensions.Logging.EventSource.csproj | 2 +- .../src/Microsoft.Extensions.Primitives.csproj | 2 +- .../pkg/Microsoft.Win32.SystemEvents.pkgproj | 2 +- .../pkg/System.ComponentModel.Composition.pkgproj | 2 +- src/libraries/System.Data.Odbc/pkg/System.Data.Odbc.pkgproj | 2 +- .../pkg/System.Diagnostics.EventLog.pkgproj | 2 +- .../src/System.Diagnostics.EventLog.csproj | 1 + .../pkg/System.Diagnostics.PerformanceCounter.pkgproj | 2 +- .../pkg/System.DirectoryServices.AccountManagement.pkgproj | 2 +- .../pkg/System.DirectoryServices.Protocols.pkgproj | 2 +- .../pkg/System.DirectoryServices.pkgproj | 2 +- .../System.Drawing.Common/pkg/System.Drawing.Common.pkgproj | 2 +- .../System.IO.Pipelines/pkg/System.IO.Pipelines.pkgproj | 2 +- src/libraries/System.Management/pkg/System.Management.pkgproj | 2 +- .../pkg/System.Reflection.MetadataLoadContext.pkgproj | 2 +- .../pkg/System.Runtime.CompilerServices.Unsafe.pkgproj | 2 +- .../pkg/System.Security.Cryptography.Pkcs.pkgproj | 2 +- .../pkg/System.Security.Permissions.pkgproj | 2 +- .../pkg/System.ServiceModel.Syndication.pkgproj | 2 +- src/libraries/System.Speech/pkg/System.Speech.pkgproj | 2 +- .../pkg/System.Text.Encoding.CodePages.pkgproj | 2 +- src/libraries/System.Text.Json/pkg/System.Text.Json.pkgproj | 2 +- .../pkg/System.Threading.AccessControl.pkgproj | 1 + .../pkg/System.Threading.Channels.pkgproj | 2 +- 26 files changed, 26 insertions(+), 23 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index d1b03d7ef8de0..73a662740acc8 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -44,6 +44,7 @@ .NETCoreApp $(NetCoreAppCurrentIdentifier),Version=v$(NetCoreAppCurrentVersion) net$(NetCoreAppCurrentVersion) + netcoreapp3.1 net$(AspNetCoreAppCurrentVersion) net$(NetCoreAppToolCurrentVersion) $(NetCoreAppCurrentIdentifier),Version=v$(NetCoreAppToolCurrentVersion) diff --git a/src/libraries/Microsoft.Extensions.Logging.Console/src/Microsoft.Extensions.Logging.Console.csproj b/src/libraries/Microsoft.Extensions.Logging.Console/src/Microsoft.Extensions.Logging.Console.csproj index 271f495a8dc21..0530b08235008 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Console/src/Microsoft.Extensions.Logging.Console.csproj +++ b/src/libraries/Microsoft.Extensions.Logging.Console/src/Microsoft.Extensions.Logging.Console.csproj @@ -57,7 +57,7 @@ - + \ No newline at end of file diff --git a/src/libraries/Microsoft.Extensions.Logging.EventSource/src/Microsoft.Extensions.Logging.EventSource.csproj b/src/libraries/Microsoft.Extensions.Logging.EventSource/src/Microsoft.Extensions.Logging.EventSource.csproj index 3823f1cfac81d..61ab1f52eeaa7 100644 --- a/src/libraries/Microsoft.Extensions.Logging.EventSource/src/Microsoft.Extensions.Logging.EventSource.csproj +++ b/src/libraries/Microsoft.Extensions.Logging.EventSource/src/Microsoft.Extensions.Logging.EventSource.csproj @@ -39,7 +39,7 @@ - + diff --git a/src/libraries/Microsoft.Extensions.Primitives/src/Microsoft.Extensions.Primitives.csproj b/src/libraries/Microsoft.Extensions.Primitives/src/Microsoft.Extensions.Primitives.csproj index 25f981a38034e..7fbed60e9ee34 100644 --- a/src/libraries/Microsoft.Extensions.Primitives/src/Microsoft.Extensions.Primitives.csproj +++ b/src/libraries/Microsoft.Extensions.Primitives/src/Microsoft.Extensions.Primitives.csproj @@ -31,6 +31,6 @@ Microsoft.Extensions.Primitives.StringSegment - + diff --git a/src/libraries/Microsoft.Win32.SystemEvents/pkg/Microsoft.Win32.SystemEvents.pkgproj b/src/libraries/Microsoft.Win32.SystemEvents/pkg/Microsoft.Win32.SystemEvents.pkgproj index 5ef768cc0786e..6d9e4dc673cb0 100644 --- a/src/libraries/Microsoft.Win32.SystemEvents/pkg/Microsoft.Win32.SystemEvents.pkgproj +++ b/src/libraries/Microsoft.Win32.SystemEvents/pkg/Microsoft.Win32.SystemEvents.pkgproj @@ -5,7 +5,7 @@ uap10.0.16299;net461;netcoreapp2.0;$(AllXamarinFrameworks) - + \ No newline at end of file diff --git a/src/libraries/System.ComponentModel.Composition/pkg/System.ComponentModel.Composition.pkgproj b/src/libraries/System.ComponentModel.Composition/pkg/System.ComponentModel.Composition.pkgproj index edf42f9de2e78..49ae7cf0595ee 100644 --- a/src/libraries/System.ComponentModel.Composition/pkg/System.ComponentModel.Composition.pkgproj +++ b/src/libraries/System.ComponentModel.Composition/pkg/System.ComponentModel.Composition.pkgproj @@ -10,7 +10,7 @@ - + diff --git a/src/libraries/System.Data.Odbc/pkg/System.Data.Odbc.pkgproj b/src/libraries/System.Data.Odbc/pkg/System.Data.Odbc.pkgproj index 3d67703c71c61..1bf618240bac7 100644 --- a/src/libraries/System.Data.Odbc/pkg/System.Data.Odbc.pkgproj +++ b/src/libraries/System.Data.Odbc/pkg/System.Data.Odbc.pkgproj @@ -5,7 +5,7 @@ uap10.0.16299;net461;netcoreapp2.0;$(AllXamarinFrameworks) - + diff --git a/src/libraries/System.Diagnostics.EventLog/pkg/System.Diagnostics.EventLog.pkgproj b/src/libraries/System.Diagnostics.EventLog/pkg/System.Diagnostics.EventLog.pkgproj index 9e45e669acb98..5c01f83bb6604 100644 --- a/src/libraries/System.Diagnostics.EventLog/pkg/System.Diagnostics.EventLog.pkgproj +++ b/src/libraries/System.Diagnostics.EventLog/pkg/System.Diagnostics.EventLog.pkgproj @@ -5,7 +5,7 @@ uap10.0.16299;net461;netcoreapp2.0;$(AllXamarinFrameworks) - + \ No newline at end of file diff --git a/src/libraries/System.Diagnostics.EventLog/src/System.Diagnostics.EventLog.csproj b/src/libraries/System.Diagnostics.EventLog/src/System.Diagnostics.EventLog.csproj index 14a4d33561620..5b55f612f8d33 100644 --- a/src/libraries/System.Diagnostics.EventLog/src/System.Diagnostics.EventLog.csproj +++ b/src/libraries/System.Diagnostics.EventLog/src/System.Diagnostics.EventLog.csproj @@ -126,6 +126,7 @@ + diff --git a/src/libraries/System.Diagnostics.PerformanceCounter/pkg/System.Diagnostics.PerformanceCounter.pkgproj b/src/libraries/System.Diagnostics.PerformanceCounter/pkg/System.Diagnostics.PerformanceCounter.pkgproj index 9b942dbe58e76..2fef4179be2b7 100644 --- a/src/libraries/System.Diagnostics.PerformanceCounter/pkg/System.Diagnostics.PerformanceCounter.pkgproj +++ b/src/libraries/System.Diagnostics.PerformanceCounter/pkg/System.Diagnostics.PerformanceCounter.pkgproj @@ -6,7 +6,7 @@ - + diff --git a/src/libraries/System.DirectoryServices.AccountManagement/pkg/System.DirectoryServices.AccountManagement.pkgproj b/src/libraries/System.DirectoryServices.AccountManagement/pkg/System.DirectoryServices.AccountManagement.pkgproj index 86e4fd6273bc7..928e56d05b1d9 100644 --- a/src/libraries/System.DirectoryServices.AccountManagement/pkg/System.DirectoryServices.AccountManagement.pkgproj +++ b/src/libraries/System.DirectoryServices.AccountManagement/pkg/System.DirectoryServices.AccountManagement.pkgproj @@ -11,7 +11,7 @@ runtimes/win/lib/net461 - + \ No newline at end of file diff --git a/src/libraries/System.DirectoryServices.Protocols/pkg/System.DirectoryServices.Protocols.pkgproj b/src/libraries/System.DirectoryServices.Protocols/pkg/System.DirectoryServices.Protocols.pkgproj index 274c781251d29..470c1346abaa0 100644 --- a/src/libraries/System.DirectoryServices.Protocols/pkg/System.DirectoryServices.Protocols.pkgproj +++ b/src/libraries/System.DirectoryServices.Protocols/pkg/System.DirectoryServices.Protocols.pkgproj @@ -12,7 +12,7 @@ runtimes/win/lib/net461 - + \ No newline at end of file diff --git a/src/libraries/System.DirectoryServices/pkg/System.DirectoryServices.pkgproj b/src/libraries/System.DirectoryServices/pkg/System.DirectoryServices.pkgproj index 6b392134854b8..c115ab6fa0896 100644 --- a/src/libraries/System.DirectoryServices/pkg/System.DirectoryServices.pkgproj +++ b/src/libraries/System.DirectoryServices/pkg/System.DirectoryServices.pkgproj @@ -13,7 +13,7 @@ runtimes/win/lib/net461 - + \ No newline at end of file diff --git a/src/libraries/System.Drawing.Common/pkg/System.Drawing.Common.pkgproj b/src/libraries/System.Drawing.Common/pkg/System.Drawing.Common.pkgproj index d478641dc5eed..16e0cc61ee482 100644 --- a/src/libraries/System.Drawing.Common/pkg/System.Drawing.Common.pkgproj +++ b/src/libraries/System.Drawing.Common/pkg/System.Drawing.Common.pkgproj @@ -6,7 +6,7 @@ - + diff --git a/src/libraries/System.IO.Pipelines/pkg/System.IO.Pipelines.pkgproj b/src/libraries/System.IO.Pipelines/pkg/System.IO.Pipelines.pkgproj index ef519b99b1a6d..a3dc8c7813961 100644 --- a/src/libraries/System.IO.Pipelines/pkg/System.IO.Pipelines.pkgproj +++ b/src/libraries/System.IO.Pipelines/pkg/System.IO.Pipelines.pkgproj @@ -19,7 +19,7 @@ - + diff --git a/src/libraries/System.Management/pkg/System.Management.pkgproj b/src/libraries/System.Management/pkg/System.Management.pkgproj index fa36b7b68fbc8..55cde1bab5c91 100644 --- a/src/libraries/System.Management/pkg/System.Management.pkgproj +++ b/src/libraries/System.Management/pkg/System.Management.pkgproj @@ -11,7 +11,7 @@ runtimes/win/lib/net461 - + \ No newline at end of file diff --git a/src/libraries/System.Reflection.MetadataLoadContext/pkg/System.Reflection.MetadataLoadContext.pkgproj b/src/libraries/System.Reflection.MetadataLoadContext/pkg/System.Reflection.MetadataLoadContext.pkgproj index 2f88ba57ac37e..e95f40804d931 100644 --- a/src/libraries/System.Reflection.MetadataLoadContext/pkg/System.Reflection.MetadataLoadContext.pkgproj +++ b/src/libraries/System.Reflection.MetadataLoadContext/pkg/System.Reflection.MetadataLoadContext.pkgproj @@ -4,7 +4,7 @@ net461;netcoreapp2.0;uap10.0.16299;$(AllXamarinFrameworks) - + diff --git a/src/libraries/System.Runtime.CompilerServices.Unsafe/pkg/System.Runtime.CompilerServices.Unsafe.pkgproj b/src/libraries/System.Runtime.CompilerServices.Unsafe/pkg/System.Runtime.CompilerServices.Unsafe.pkgproj index 46ea9e67b0a09..90d23508d8144 100644 --- a/src/libraries/System.Runtime.CompilerServices.Unsafe/pkg/System.Runtime.CompilerServices.Unsafe.pkgproj +++ b/src/libraries/System.Runtime.CompilerServices.Unsafe/pkg/System.Runtime.CompilerServices.Unsafe.pkgproj @@ -18,7 +18,7 @@ - + \ No newline at end of file diff --git a/src/libraries/System.Security.Cryptography.Pkcs/pkg/System.Security.Cryptography.Pkcs.pkgproj b/src/libraries/System.Security.Cryptography.Pkcs/pkg/System.Security.Cryptography.Pkcs.pkgproj index 0fd0f8c5b4f17..0eeb304e2fb46 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/pkg/System.Security.Cryptography.Pkcs.pkgproj +++ b/src/libraries/System.Security.Cryptography.Pkcs/pkg/System.Security.Cryptography.Pkcs.pkgproj @@ -5,7 +5,7 @@ net461;netcoreapp2.0;uap10.0.16299;$(AllXamarinFrameworks) - + diff --git a/src/libraries/System.Security.Permissions/pkg/System.Security.Permissions.pkgproj b/src/libraries/System.Security.Permissions/pkg/System.Security.Permissions.pkgproj index cb976d3857d7a..c4591c3ad06d8 100644 --- a/src/libraries/System.Security.Permissions/pkg/System.Security.Permissions.pkgproj +++ b/src/libraries/System.Security.Permissions/pkg/System.Security.Permissions.pkgproj @@ -5,7 +5,7 @@ netcoreapp2.0;net461;uap10.0.16299;$(AllXamarinFrameworks) - + \ No newline at end of file diff --git a/src/libraries/System.ServiceModel.Syndication/pkg/System.ServiceModel.Syndication.pkgproj b/src/libraries/System.ServiceModel.Syndication/pkg/System.ServiceModel.Syndication.pkgproj index 9e1434e92080c..aa80ef9e3dc20 100644 --- a/src/libraries/System.ServiceModel.Syndication/pkg/System.ServiceModel.Syndication.pkgproj +++ b/src/libraries/System.ServiceModel.Syndication/pkg/System.ServiceModel.Syndication.pkgproj @@ -5,7 +5,7 @@ uap10.0.16299;net461;netcoreapp2.0;$(AllXamarinFrameworks) - + \ No newline at end of file diff --git a/src/libraries/System.Speech/pkg/System.Speech.pkgproj b/src/libraries/System.Speech/pkg/System.Speech.pkgproj index b34710daef76e..fd8103dc52b75 100644 --- a/src/libraries/System.Speech/pkg/System.Speech.pkgproj +++ b/src/libraries/System.Speech/pkg/System.Speech.pkgproj @@ -8,7 +8,7 @@ true - + diff --git a/src/libraries/System.Text.Encoding.CodePages/pkg/System.Text.Encoding.CodePages.pkgproj b/src/libraries/System.Text.Encoding.CodePages/pkg/System.Text.Encoding.CodePages.pkgproj index 7150d80c8aa21..42c9d69940907 100644 --- a/src/libraries/System.Text.Encoding.CodePages/pkg/System.Text.Encoding.CodePages.pkgproj +++ b/src/libraries/System.Text.Encoding.CodePages/pkg/System.Text.Encoding.CodePages.pkgproj @@ -9,7 +9,7 @@ - + diff --git a/src/libraries/System.Text.Json/pkg/System.Text.Json.pkgproj b/src/libraries/System.Text.Json/pkg/System.Text.Json.pkgproj index ac2d21ef89d61..2b335bb4c142e 100644 --- a/src/libraries/System.Text.Json/pkg/System.Text.Json.pkgproj +++ b/src/libraries/System.Text.Json/pkg/System.Text.Json.pkgproj @@ -15,7 +15,7 @@ .NETCoreApp;UAP - + \ No newline at end of file diff --git a/src/libraries/System.Threading.AccessControl/pkg/System.Threading.AccessControl.pkgproj b/src/libraries/System.Threading.AccessControl/pkg/System.Threading.AccessControl.pkgproj index 7c7145ce3e491..02cd7bd85f129 100644 --- a/src/libraries/System.Threading.AccessControl/pkg/System.Threading.AccessControl.pkgproj +++ b/src/libraries/System.Threading.AccessControl/pkg/System.Threading.AccessControl.pkgproj @@ -7,6 +7,7 @@ + \ No newline at end of file diff --git a/src/libraries/System.Threading.Channels/pkg/System.Threading.Channels.pkgproj b/src/libraries/System.Threading.Channels/pkg/System.Threading.Channels.pkgproj index 28fa02b0c608e..787314714ce21 100644 --- a/src/libraries/System.Threading.Channels/pkg/System.Threading.Channels.pkgproj +++ b/src/libraries/System.Threading.Channels/pkg/System.Threading.Channels.pkgproj @@ -12,7 +12,7 @@ - + From 8b4a4713fdb6234e6b3c7284178373c8f42d94ce Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Tue, 22 Jun 2021 13:22:32 +0200 Subject: [PATCH 02/25] Add NetCoreAppCurrent to S.Numerics.Tensors --- .../pkg/System.Numerics.Tensors.pkgproj | 1 + .../ref/System.Numerics.Tensors.cs | 16 ++++++++-------- .../ref/System.Numerics.Tensors.csproj | 10 ++++++++-- .../src/System.Numerics.Tensors.csproj | 13 +++++++++++-- .../src/System/Numerics/Tensors/SparseTensor.cs | 2 +- .../src/System/Numerics/Tensors/Tensor.cs | 6 +++--- 6 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/libraries/System.Numerics.Tensors/pkg/System.Numerics.Tensors.pkgproj b/src/libraries/System.Numerics.Tensors/pkg/System.Numerics.Tensors.pkgproj index 75855f8b61ef0..372a4d92c7e3f 100644 --- a/src/libraries/System.Numerics.Tensors/pkg/System.Numerics.Tensors.pkgproj +++ b/src/libraries/System.Numerics.Tensors/pkg/System.Numerics.Tensors.pkgproj @@ -11,6 +11,7 @@ + diff --git a/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.cs b/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.cs index b54d42ebf768a..3161a4c7e780c 100644 --- a/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.cs +++ b/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.cs @@ -97,7 +97,7 @@ protected Tensor(System.ReadOnlySpan dimensions, bool reverseStride) { } int System.Collections.ICollection.Count { get { throw null; } } bool System.Collections.ICollection.IsSynchronized { get { throw null; } } object System.Collections.ICollection.SyncRoot { get { throw null; } } - object System.Collections.IList.this[int index] { get { throw null; } set { } } + object? System.Collections.IList.this[int index] { get { throw null; } set { } } public abstract System.Numerics.Tensors.Tensor Clone(); public virtual System.Numerics.Tensors.Tensor CloneEmpty() { throw null; } public virtual System.Numerics.Tensors.Tensor CloneEmpty(System.ReadOnlySpan dimensions) { throw null; } @@ -139,15 +139,15 @@ void System.Collections.Generic.IList.Insert(int index, T item) { } void System.Collections.Generic.IList.RemoveAt(int index) { } void System.Collections.ICollection.CopyTo(System.Array array, int index) { } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } - int System.Collections.IList.Add(object value) { throw null; } + int System.Collections.IList.Add(object? value) { throw null; } void System.Collections.IList.Clear() { } - bool System.Collections.IList.Contains(object value) { throw null; } - int System.Collections.IList.IndexOf(object value) { throw null; } - void System.Collections.IList.Insert(int index, object value) { } - void System.Collections.IList.Remove(object value) { } + bool System.Collections.IList.Contains(object? value) { throw null; } + int System.Collections.IList.IndexOf(object? value) { throw null; } + void System.Collections.IList.Insert(int index, object? value) { } + void System.Collections.IList.Remove(object? value) { } void System.Collections.IList.RemoveAt(int index) { } - int System.Collections.IStructuralComparable.CompareTo(object other, System.Collections.IComparer comparer) { throw null; } - bool System.Collections.IStructuralEquatable.Equals(object other, System.Collections.IEqualityComparer comparer) { throw null; } + int System.Collections.IStructuralComparable.CompareTo(object? other, System.Collections.IComparer comparer) { throw null; } + bool System.Collections.IStructuralEquatable.Equals(object? other, System.Collections.IEqualityComparer comparer) { throw null; } int System.Collections.IStructuralEquatable.GetHashCode(System.Collections.IEqualityComparer comparer) { throw null; } public virtual System.Numerics.Tensors.CompressedSparseTensor ToCompressedSparseTensor() { throw null; } public virtual System.Numerics.Tensors.DenseTensor ToDenseTensor() { throw null; } diff --git a/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.csproj b/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.csproj index ae9c55011f812..ed6005dc03048 100644 --- a/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.csproj +++ b/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.csproj @@ -1,12 +1,18 @@ - netstandard2.0;net461 + $(NetCoreAppCurrent);netstandard2.0;net461 enable + - + + + + + + \ No newline at end of file diff --git a/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj b/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj index b87c193207be5..8dfed2f6283d5 100644 --- a/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj +++ b/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj @@ -1,9 +1,10 @@ true - netstandard2.0;net461 + $(NetCoreAppCurrent);netstandard2.0;net461 enable + @@ -13,7 +14,15 @@ - + + + + + + + + + diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/SparseTensor.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/SparseTensor.cs index 9c40bb49a898f..7196a528e9da0 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/SparseTensor.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/SparseTensor.cs @@ -71,7 +71,7 @@ internal SparseTensor(Array fromArray, bool reverseStride = false) : base(fromAr public override T GetValue(int index) { - if (!values.TryGetValue(index, out T value)) + if (!values.TryGetValue(index, out T? value)) { value = Zero; } diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/Tensor.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/Tensor.cs index 270da201c53b4..83c6947d76a50 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/Tensor.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/Tensor.cs @@ -705,7 +705,7 @@ internal Enumerator(Tensor tensor) _tensor = tensor; _index = 0; - Current = default; + Current = default!; } public T Current { get; private set; } @@ -722,7 +722,7 @@ public bool MoveNext() } else { - Current = default; + Current = default!; return false; } } @@ -733,7 +733,7 @@ public bool MoveNext() public void Reset() { _index = 0; - Current = default; + Current = default!; } /// From e91462ff32d8cc9a829b3c4070ffdb6839eaf0a3 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Tue, 22 Jun 2021 13:22:52 +0200 Subject: [PATCH 03/25] Add NetCoreAppCurrent to S.T.AccessControl --- .../ref/System.Threading.AccessControl.csproj | 7 ++++++- .../src/System.Threading.AccessControl.csproj | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Threading.AccessControl/ref/System.Threading.AccessControl.csproj b/src/libraries/System.Threading.AccessControl/ref/System.Threading.AccessControl.csproj index 396bb7caf52f3..3f57e01ad4d1b 100644 --- a/src/libraries/System.Threading.AccessControl/ref/System.Threading.AccessControl.csproj +++ b/src/libraries/System.Threading.AccessControl/ref/System.Threading.AccessControl.csproj @@ -1,6 +1,6 @@ - netstandard2.0;net461 + $(NetCoreAppCurrent);netstandard2.0;net461 enable @@ -8,6 +8,11 @@ + + + + + diff --git a/src/libraries/System.Threading.AccessControl/src/System.Threading.AccessControl.csproj b/src/libraries/System.Threading.AccessControl/src/System.Threading.AccessControl.csproj index 4e2e14f344db1..d381ca2177a82 100644 --- a/src/libraries/System.Threading.AccessControl/src/System.Threading.AccessControl.csproj +++ b/src/libraries/System.Threading.AccessControl/src/System.Threading.AccessControl.csproj @@ -1,6 +1,6 @@ - netstandard2.0-windows;netstandard2.0;net461-windows + $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent);netstandard2.0-windows;netstandard2.0;net461-windows true enable @@ -50,6 +50,13 @@ + + + + + + + From 73e70c62a3ebbb006008fa639f934d7a5248c29b Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Tue, 22 Jun 2021 14:16:10 +0200 Subject: [PATCH 04/25] Add NetCoreAppCurrent to System.Memory.Data --- .../pkg/System.Memory.Data.pkgproj | 1 + .../ref/System.Memory.Data.cs | 2 +- .../ref/System.Memory.Data.csproj | 7 +++++-- .../src/System.Memory.Data.csproj | 21 +++++++++++++++---- .../src/System/BinaryData.cs | 4 ++-- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/libraries/System.Memory.Data/pkg/System.Memory.Data.pkgproj b/src/libraries/System.Memory.Data/pkg/System.Memory.Data.pkgproj index f7170bd421917..4427a3e822abf 100644 --- a/src/libraries/System.Memory.Data/pkg/System.Memory.Data.pkgproj +++ b/src/libraries/System.Memory.Data/pkg/System.Memory.Data.pkgproj @@ -4,6 +4,7 @@ net461;netcoreapp2.0;uap10.0.16299;$(AllXamarinFrameworks) + \ No newline at end of file diff --git a/src/libraries/System.Memory.Data/ref/System.Memory.Data.cs b/src/libraries/System.Memory.Data/ref/System.Memory.Data.cs index d2bb7a7622d1d..302a4da145f0f 100644 --- a/src/libraries/System.Memory.Data/ref/System.Memory.Data.cs +++ b/src/libraries/System.Memory.Data/ref/System.Memory.Data.cs @@ -27,7 +27,7 @@ public BinaryData(string data) { } public static implicit operator System.ReadOnlySpan (System.BinaryData? data) { throw null; } public byte[] ToArray() { throw null; } public System.ReadOnlyMemory ToMemory() { throw null; } - public T ToObjectFromJson(System.Text.Json.JsonSerializerOptions? options = null) { throw null; } + public T? ToObjectFromJson(System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public System.IO.Stream ToStream() { throw null; } public override string ToString() { throw null; } } diff --git a/src/libraries/System.Memory.Data/ref/System.Memory.Data.csproj b/src/libraries/System.Memory.Data/ref/System.Memory.Data.csproj index c5537ac47ec0e..30f156a04fc00 100644 --- a/src/libraries/System.Memory.Data/ref/System.Memory.Data.csproj +++ b/src/libraries/System.Memory.Data/ref/System.Memory.Data.csproj @@ -1,13 +1,16 @@ - net461;netstandard2.0 + $(NetCoreAppCurrent);netstandard2.0;net461 enable - + + + + diff --git a/src/libraries/System.Memory.Data/src/System.Memory.Data.csproj b/src/libraries/System.Memory.Data/src/System.Memory.Data.csproj index 892ebb90f85d8..b7b49395879d2 100644 --- a/src/libraries/System.Memory.Data/src/System.Memory.Data.csproj +++ b/src/libraries/System.Memory.Data/src/System.Memory.Data.csproj @@ -1,16 +1,29 @@  - net461;netstandard2.0 + $(NetCoreAppCurrent);netstandard2.0;net461 true enable + - - + + + - + + + + + + + + + + diff --git a/src/libraries/System.Memory.Data/src/System/BinaryData.cs b/src/libraries/System.Memory.Data/src/System/BinaryData.cs index 35c1fcf9ae1cd..b0e56d1e7bae3 100644 --- a/src/libraries/System.Memory.Data/src/System/BinaryData.cs +++ b/src/libraries/System.Memory.Data/src/System/BinaryData.cs @@ -230,9 +230,9 @@ public override unsafe string ToString() /// converted to. /// The to use when serializing to JSON. /// The data converted to the specified type. - public T ToObjectFromJson(JsonSerializerOptions? options = default) + public T? ToObjectFromJson(JsonSerializerOptions? options = default) { - return (T)JsonSerializer.Deserialize(_bytes.Span, typeof(T), options); + return JsonSerializer.Deserialize(_bytes.Span, options); } /// From ef78b74ccddf62a160de47543257bc7b7f0ea74d Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Tue, 22 Jun 2021 17:06:02 +0200 Subject: [PATCH 05/25] Add NetCoreAppCurrent to S.Composition.* projects --- .../System.Composition.AttributedModel.pkgproj | 1 + .../System.Composition.AttributedModel.csproj | 7 ++++++- .../pkg/System.Composition.Convention.pkgproj | 1 + .../src/System.Composition.Convention.csproj | 12 +++++++++++- .../pkg/System.Composition.Hosting.pkgproj | 1 + .../src/System.Composition.Hosting.csproj | 16 ++++++++++++++-- .../pkg/System.Composition.Runtime.pkgproj | 1 + .../src/System.Composition.Runtime.csproj | 9 ++++++++- .../pkg/System.Composition.TypedParts.pkgproj | 1 + .../src/System.Composition.TypedParts.csproj | 11 ++++++++++- 10 files changed, 54 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.Composition.AttributedModel/pkg/System.Composition.AttributedModel.pkgproj b/src/libraries/System.Composition.AttributedModel/pkg/System.Composition.AttributedModel.pkgproj index 340da4ff11737..4c2c1ff8a36a9 100644 --- a/src/libraries/System.Composition.AttributedModel/pkg/System.Composition.AttributedModel.pkgproj +++ b/src/libraries/System.Composition.AttributedModel/pkg/System.Composition.AttributedModel.pkgproj @@ -6,6 +6,7 @@ + \ No newline at end of file diff --git a/src/libraries/System.Composition.AttributedModel/src/System.Composition.AttributedModel.csproj b/src/libraries/System.Composition.AttributedModel/src/System.Composition.AttributedModel.csproj index 999ec09ad8fc2..7d49a3802f966 100644 --- a/src/libraries/System.Composition.AttributedModel/src/System.Composition.AttributedModel.csproj +++ b/src/libraries/System.Composition.AttributedModel/src/System.Composition.AttributedModel.csproj @@ -1,7 +1,8 @@ - netstandard2.0;net461 + $(NetCoreAppCurrent);netstandard2.0;net461 + @@ -17,4 +18,8 @@ + + + + \ No newline at end of file diff --git a/src/libraries/System.Composition.Convention/pkg/System.Composition.Convention.pkgproj b/src/libraries/System.Composition.Convention/pkg/System.Composition.Convention.pkgproj index 8239d4a17e689..957c0d82866a0 100644 --- a/src/libraries/System.Composition.Convention/pkg/System.Composition.Convention.pkgproj +++ b/src/libraries/System.Composition.Convention/pkg/System.Composition.Convention.pkgproj @@ -6,6 +6,7 @@ + \ No newline at end of file diff --git a/src/libraries/System.Composition.Convention/src/System.Composition.Convention.csproj b/src/libraries/System.Composition.Convention/src/System.Composition.Convention.csproj index 948a3a7934dc6..500ab5bb2a271 100644 --- a/src/libraries/System.Composition.Convention/src/System.Composition.Convention.csproj +++ b/src/libraries/System.Composition.Convention/src/System.Composition.Convention.csproj @@ -1,8 +1,9 @@ - netstandard2.0;net461 + $(NetCoreAppCurrent);netstandard2.0;net461 false + @@ -21,7 +22,16 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/libraries/System.Composition.Hosting/pkg/System.Composition.Hosting.pkgproj b/src/libraries/System.Composition.Hosting/pkg/System.Composition.Hosting.pkgproj index dcc53d4d65c80..d319cbd0c8e27 100644 --- a/src/libraries/System.Composition.Hosting/pkg/System.Composition.Hosting.pkgproj +++ b/src/libraries/System.Composition.Hosting/pkg/System.Composition.Hosting.pkgproj @@ -6,6 +6,7 @@ + \ No newline at end of file diff --git a/src/libraries/System.Composition.Hosting/src/System.Composition.Hosting.csproj b/src/libraries/System.Composition.Hosting/src/System.Composition.Hosting.csproj index 66c1f0e8fe198..437ad767826ff 100644 --- a/src/libraries/System.Composition.Hosting/src/System.Composition.Hosting.csproj +++ b/src/libraries/System.Composition.Hosting/src/System.Composition.Hosting.csproj @@ -1,8 +1,9 @@ - netstandard2.0;net461 + $(NetCoreAppCurrent);netstandard2.0;net461 false + @@ -31,10 +32,21 @@ + - + + + + + + + + + + + \ No newline at end of file diff --git a/src/libraries/System.Composition.Runtime/pkg/System.Composition.Runtime.pkgproj b/src/libraries/System.Composition.Runtime/pkg/System.Composition.Runtime.pkgproj index c72e14fe909f7..acdef61a398d0 100644 --- a/src/libraries/System.Composition.Runtime/pkg/System.Composition.Runtime.pkgproj +++ b/src/libraries/System.Composition.Runtime/pkg/System.Composition.Runtime.pkgproj @@ -6,6 +6,7 @@ + \ No newline at end of file diff --git a/src/libraries/System.Composition.Runtime/src/System.Composition.Runtime.csproj b/src/libraries/System.Composition.Runtime/src/System.Composition.Runtime.csproj index cdd6654321fe4..b5ecf044a581a 100644 --- a/src/libraries/System.Composition.Runtime/src/System.Composition.Runtime.csproj +++ b/src/libraries/System.Composition.Runtime/src/System.Composition.Runtime.csproj @@ -1,8 +1,9 @@ System.Composition - netstandard2.0;net461 + $(NetCoreAppCurrent);netstandard2.0;net461 + @@ -12,4 +13,10 @@ + + + + + + \ No newline at end of file diff --git a/src/libraries/System.Composition.TypedParts/pkg/System.Composition.TypedParts.pkgproj b/src/libraries/System.Composition.TypedParts/pkg/System.Composition.TypedParts.pkgproj index e884c4bc186fb..e7ea55ed613c0 100644 --- a/src/libraries/System.Composition.TypedParts/pkg/System.Composition.TypedParts.pkgproj +++ b/src/libraries/System.Composition.TypedParts/pkg/System.Composition.TypedParts.pkgproj @@ -6,6 +6,7 @@ + \ No newline at end of file diff --git a/src/libraries/System.Composition.TypedParts/src/System.Composition.TypedParts.csproj b/src/libraries/System.Composition.TypedParts/src/System.Composition.TypedParts.csproj index d22e4354ffee4..c8828d012e679 100644 --- a/src/libraries/System.Composition.TypedParts/src/System.Composition.TypedParts.csproj +++ b/src/libraries/System.Composition.TypedParts/src/System.Composition.TypedParts.csproj @@ -1,9 +1,10 @@ System.Composition - netstandard2.0;net461 + $(NetCoreAppCurrent);netstandard2.0;net461 false + @@ -29,9 +30,17 @@ + + + + + + + + \ No newline at end of file From 39f809cd3e4c50294cc46d4dc49c814a82d044d2 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Tue, 22 Jun 2021 17:55:34 +0200 Subject: [PATCH 06/25] Add NetCoreAppCurrent to System.IO.Packaging --- .../pkg/System.IO.Packaging.pkgproj | 1 + .../ref/System.IO.Packaging.csproj | 10 ++++++++-- .../src/System.IO.Packaging.csproj | 12 ++++++++++- .../src/System/IO/Packaging/PackUriHelper.cs | 6 +++++- .../System/IO/Packaging/PackagingUtilities.cs | 2 +- .../Packaging/PartBasedPackageProperties.cs | 2 +- .../IO/Packaging/XmlCompatibilityReader.cs | 16 ++++++++------- .../System/IO/Packaging/XmlWrappingReader.cs | 18 ++++++++--------- .../src/System/IO/Packaging/ZipPackage.cs | 20 +++++++++---------- 9 files changed, 55 insertions(+), 32 deletions(-) diff --git a/src/libraries/System.IO.Packaging/pkg/System.IO.Packaging.pkgproj b/src/libraries/System.IO.Packaging/pkg/System.IO.Packaging.pkgproj index 6335a71313f60..14c8ca9ff74c9 100644 --- a/src/libraries/System.IO.Packaging/pkg/System.IO.Packaging.pkgproj +++ b/src/libraries/System.IO.Packaging/pkg/System.IO.Packaging.pkgproj @@ -8,6 +8,7 @@ + \ No newline at end of file diff --git a/src/libraries/System.IO.Packaging/ref/System.IO.Packaging.csproj b/src/libraries/System.IO.Packaging/ref/System.IO.Packaging.csproj index 3d0cb8b6ff79f..c2ea960539aeb 100644 --- a/src/libraries/System.IO.Packaging/ref/System.IO.Packaging.csproj +++ b/src/libraries/System.IO.Packaging/ref/System.IO.Packaging.csproj @@ -1,13 +1,19 @@ - netstandard2.0;net461 + $(NetCoreAppCurrent);netstandard2.0;net461 enable - + + + + + + + diff --git a/src/libraries/System.IO.Packaging/src/System.IO.Packaging.csproj b/src/libraries/System.IO.Packaging/src/System.IO.Packaging.csproj index 1f52d164d2d93..a0603ef6e1370 100644 --- a/src/libraries/System.IO.Packaging/src/System.IO.Packaging.csproj +++ b/src/libraries/System.IO.Packaging/src/System.IO.Packaging.csproj @@ -1,13 +1,15 @@ true - netstandard2.0;net461 + $(NetCoreAppCurrent);netstandard2.0;net461 enable + true + @@ -38,6 +40,14 @@ + + + + + + + + diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.cs index 46f02c47e8e93..179e71e3438bb 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.cs @@ -466,7 +466,11 @@ private static void ThrowIfFragmentPresent(string partName) private static ArgumentException? GetExceptionIfFragmentPresent(string partName) { - if (partName.Contains("#")) // string.Contains(char) is .NetCore2.1+ specific +#if NETCOREAPP + if (partName.Contains('#')) // string.Contains(char) is .NetCore2.1+ specific +#else + if (partName.Contains("#")) +#endif return new ArgumentException(SR.PartUriCannotHaveAFragment); else return null; diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackagingUtilities.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackagingUtilities.cs index 32f9739714151..f87baba3e95df 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackagingUtilities.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackagingUtilities.cs @@ -33,7 +33,7 @@ internal static void PerformInitialReadAndVerifyEncoding(XmlReader reader) //If the first node is XmlDeclaration we check to see if the encoding attribute is present if (reader.Read() && reader.NodeType == XmlNodeType.XmlDeclaration && reader.Depth == 0) { - string encoding = reader.GetAttribute(EncodingAttribute); + string? encoding = reader.GetAttribute(EncodingAttribute); if (!string.IsNullOrEmpty(encoding)) { diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PartBasedPackageProperties.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PartBasedPackageProperties.cs index f4ed524180ef1..20885d57997e3 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PartBasedPackageProperties.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PartBasedPackageProperties.cs @@ -600,7 +600,7 @@ private void ParseCorePropertyPart(PackagePart part) internal static void ValidateXsiType(XmlReader reader, object ns, string name) { // Get the value of xsi;type - string typeValue = reader.GetAttribute(PackageXmlStringTable.GetXmlString(PackageXmlEnum.Type), + string? typeValue = reader.GetAttribute(PackageXmlStringTable.GetXmlString(PackageXmlEnum.Type), PackageXmlStringTable.GetXmlString(PackageXmlEnum.XmlSchemaInstanceNamespace)); // Missing xsi:type diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/XmlCompatibilityReader.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/XmlCompatibilityReader.cs index d24b354558bb0..df65e29fdf149 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/XmlCompatibilityReader.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/XmlCompatibilityReader.cs @@ -405,11 +405,11 @@ public override string GetAttribute(int i) /// /// The value of the specified attribute. If the attribute is not found, a null reference is returned. /// - public override string? GetAttribute(string localName, string namespaceURI) + public override string? GetAttribute(string localName, string? namespaceURI) { string? result = null; - if (_ignoredAttributeCount == 0 || !ShouldIgnoreNamespace(namespaceURI)) + if (_ignoredAttributeCount == 0 || !ShouldIgnoreNamespace(namespaceURI!)) { // if the current element does not have any attributes that should be ignored or // the namespace provided is not ignorable, call Reader method @@ -503,7 +503,7 @@ public override bool MoveToAttribute(string name) /// /// true if the attribute is found; otherwise, false. If false, the reader's position does not change. /// - public override bool MoveToAttribute(string localName, string namespaceURI) + public override bool MoveToAttribute(string localName, string? namespaceURI) { bool result; @@ -518,7 +518,7 @@ public override bool MoveToAttribute(string localName, string namespaceURI) result = Reader.MoveToAttribute(localName, namespaceURI); - if (result && ShouldIgnoreNamespace(namespaceURI)) + if (result && ShouldIgnoreNamespace(namespaceURI!)) { result = false; RestoreReaderPosition(); @@ -594,7 +594,7 @@ public override bool MoveToNextAttribute() /// public override string? LookupNamespace(string prefix) { - string namespaceName = Reader.LookupNamespace(prefix); + string? namespaceName = Reader.LookupNamespace(prefix); if (namespaceName != null) { @@ -613,6 +613,7 @@ public override bool MoveToNextAttribute() /// for the xmlns attribute reflects all the /// compatibility (subsuming) rules. /// +#pragma warning disable CS8764 // Nullability of return type doesn't match overridden member public override string? Value { get @@ -631,6 +632,7 @@ public override string? Value return Reader.Value; } } +#pragma warning restore CS8764 /// /// Gets the namespace URI (as defined in the W3C Namespace specification) of the node @@ -693,7 +695,7 @@ private void RestoreReaderPosition() // Restore reader state from SaveReaderPosition if (_inAttribute) { - Reader.MoveToAttribute(_currentName); + Reader.MoveToAttribute(_currentName!); } else { @@ -1141,7 +1143,7 @@ private void HandleChoice(int elementDepth, ref bool more) Error(SR.XCRChoiceAfterFallback); } - string requiresValue = Reader.GetAttribute(Requires); + string? requiresValue = Reader.GetAttribute(Requires); if (requiresValue == null) { diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/XmlWrappingReader.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/XmlWrappingReader.cs index f94c528ebc4dd..370b566b5b0a6 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/XmlWrappingReader.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/XmlWrappingReader.cs @@ -22,14 +22,14 @@ internal XmlWrappingReader(XmlReader baseReader) Reader = baseReader; } - public override XmlReaderSettings Settings { get { return _reader.Settings; } } + public override XmlReaderSettings? Settings { get { return _reader.Settings; } } public override XmlNodeType NodeType { get { return _reader.NodeType; } } public override string Name { get { return _reader.Name; } } public override string LocalName { get { return _reader.LocalName; } } public override string NamespaceURI { get { return _reader.NamespaceURI; } } public override string Prefix { get { return _reader.Prefix; } } public override bool HasValue { get { return _reader.HasValue; } } - public override string? Value { get { return _reader.Value; } } + public override string Value { get { return _reader.Value; } } public override int Depth { get { return _reader.Depth; } } public override string BaseURI { get { return _reader.BaseURI; } } public override bool IsEmptyElement { get { return _reader.IsEmptyElement; } } @@ -39,8 +39,8 @@ internal XmlWrappingReader(XmlReader baseReader) public override System.Type ValueType { get { return _reader.ValueType; } } public override int AttributeCount { get { return _reader.AttributeCount; } } public override string this[int i] { get { return _reader[i]; } } - public override string this[string name] { get { return _reader[name]; } } - public override string this[string name, string namespaceURI] { get { return _reader[name, namespaceURI]; } } + public override string? this[string name] { get { return _reader[name]; } } + public override string? this[string name, string? namespaceURI] { get { return _reader[name, namespaceURI]; } } public override bool CanResolveEntity { get { return _reader.CanResolveEntity; } } public override bool EOF { get { return _reader.EOF; } } public override ReadState ReadState { get { return _reader.ReadState; } } @@ -52,7 +52,7 @@ internal XmlWrappingReader(XmlReader baseReader) return _reader.GetAttribute(name); } - public override string? GetAttribute(string name, string namespaceURI) + public override string? GetAttribute(string name, string? namespaceURI) { return _reader.GetAttribute(name, namespaceURI); } @@ -67,7 +67,7 @@ public override bool MoveToAttribute(string name) return _reader.MoveToAttribute(name); } - public override bool MoveToAttribute(string name, string ns) + public override bool MoveToAttribute(string name, string? ns) { return _reader.MoveToAttribute(name, ns); } @@ -109,12 +109,12 @@ public override void Skip() string? IXmlNamespaceResolver.LookupPrefix(string namespaceName) { - return (_readerAsResolver == null) ? null : _readerAsResolver.LookupPrefix(namespaceName); + return _readerAsResolver?.LookupPrefix(namespaceName); } - IDictionary? IXmlNamespaceResolver.GetNamespacesInScope(XmlNamespaceScope scope) + IDictionary IXmlNamespaceResolver.GetNamespacesInScope(XmlNamespaceScope scope) { - return (_readerAsResolver == null) ? null : _readerAsResolver.GetNamespacesInScope(scope); + return _readerAsResolver?.GetNamespacesInScope(scope)!; } public override void ResolveEntity() diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ZipPackage.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ZipPackage.cs index fb4f41723ded8..8f4fd15ddfc5a 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ZipPackage.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ZipPackage.cs @@ -851,17 +851,17 @@ private void ProcessDefaultTagAttributes(XmlReader reader) // get the required Extension and ContentType attributes - string extensionAttributeValue = reader.GetAttribute(ExtensionAttributeName); + string? extensionAttributeValue = reader.GetAttribute(ExtensionAttributeName); ValidateXmlAttribute(ExtensionAttributeName, extensionAttributeValue, DefaultTagName, reader); - string contentTypeAttributeValue = reader.GetAttribute(ContentTypeAttributeName); + string? contentTypeAttributeValue = reader.GetAttribute(ContentTypeAttributeName); ThrowIfXmlAttributeMissing(ContentTypeAttributeName, contentTypeAttributeValue, DefaultTagName, reader); // The extensions are stored in the Default Dictionary in their original form , but they are compared // in a normalized manner using the ExtensionComparer. PackUriHelper.ValidatedPartUri temporaryUri = PackUriHelper.ValidatePartUri( new Uri(TemporaryPartNameWithoutExtension + extensionAttributeValue, UriKind.Relative)); - _defaultDictionary.Add(temporaryUri.PartUriExtension, new ContentType(contentTypeAttributeValue)); + _defaultDictionary.Add(temporaryUri.PartUriExtension, new ContentType(contentTypeAttributeValue!)); //Skip the EndElement for Default Tag if (!reader.IsEmptyElement) @@ -878,20 +878,20 @@ private void ProcessOverrideTagAttributes(XmlReader reader) // get the required Extension and ContentType attributes - string partNameAttributeValue = reader.GetAttribute(PartNameAttributeName); + string? partNameAttributeValue = reader.GetAttribute(PartNameAttributeName); ValidateXmlAttribute(PartNameAttributeName, partNameAttributeValue, OverrideTagName, reader); - string contentTypeAttributeValue = reader.GetAttribute(ContentTypeAttributeName); + string? contentTypeAttributeValue = reader.GetAttribute(ContentTypeAttributeName); ThrowIfXmlAttributeMissing(ContentTypeAttributeName, contentTypeAttributeValue, OverrideTagName, reader); - PackUriHelper.ValidatedPartUri partUri = PackUriHelper.ValidatePartUri(new Uri(partNameAttributeValue, UriKind.Relative)); + PackUriHelper.ValidatedPartUri partUri = PackUriHelper.ValidatePartUri(new Uri(partNameAttributeValue!, UriKind.Relative)); //Lazy initializing - ensure that the override dictionary has been initialized EnsureOverrideDictionary(); // The part Uris are stored in the Override Dictionary in their original form , but they are compared // in a normalized manner using PartUriComparer. - _overrideDictionary.Add(partUri, new ContentType(contentTypeAttributeValue)); + _overrideDictionary.Add(partUri, new ContentType(contentTypeAttributeValue!)); //Skip the EndElement for Override Tag if (!reader.IsEmptyElement) @@ -957,19 +957,19 @@ private void WriteDefaultElement(XmlWriter xmlWriter, string extension, ContentT } //Validate if the required XML attribute is present and not an empty string - private void ValidateXmlAttribute(string attributeName, string attributeValue, string tagName, XmlReader reader) + private void ValidateXmlAttribute(string attributeName, string? attributeValue, string tagName, XmlReader reader) { ThrowIfXmlAttributeMissing(attributeName, attributeValue, tagName, reader); //Checking for empty attribute - if (attributeValue.Length == 0) + if (attributeValue!.Length == 0) throw new XmlException(SR.Format(SR.RequiredAttributeEmpty, tagName, attributeName), null, ((IXmlLineInfo)reader).LineNumber, ((IXmlLineInfo)reader).LinePosition); } //Validate if the required Content type XML attribute is present //Content type of a part can be empty - private void ThrowIfXmlAttributeMissing(string attributeName, string attributeValue, string tagName, XmlReader reader) + private void ThrowIfXmlAttributeMissing(string attributeName, string? attributeValue, string tagName, XmlReader reader) { if (attributeValue == null) throw new XmlException(SR.Format(SR.RequiredAttributeMissing, tagName, attributeName), null, ((IXmlLineInfo)reader).LineNumber, ((IXmlLineInfo)reader).LinePosition); From 61dd12145dfadbca1dacbedfb28009dd2b074413 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Tue, 22 Jun 2021 18:52:27 +0200 Subject: [PATCH 07/25] Add NetCoreAppCurrent config to System.IO.Ports Adding a NetCoreAppCurrent configuration to System.IO.Ports and reducing package size, build times and platform specific assets by using runtime checks on Unix derivates for the slightly diverging SerialPort implementation. Contributes to https://github.com/dotnet/runtime/issues/54012 --- .../pkg/System.IO.Ports.pkgproj | 1 + .../ref/System.IO.Ports.csproj | 7 +- .../src/System.IO.Ports.csproj | 40 +++++++---- .../src/System/IO/Ports/SerialPort.FreeBSD.cs | 36 ---------- .../src/System/IO/Ports/SerialPort.OSX.cs | 38 ---------- ...SerialPort.Linux.cs => SerialPort.Unix.cs} | 71 +++++++++++++++++++ .../src/System/IO/Ports/SerialPort.Win32.cs | 4 -- .../src/System/IO/Ports/SerialStream.Unix.cs | 34 +++++++-- 8 files changed, 134 insertions(+), 97 deletions(-) delete mode 100644 src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.FreeBSD.cs delete mode 100644 src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.OSX.cs rename src/libraries/System.IO.Ports/src/System/IO/Ports/{SerialPort.Linux.cs => SerialPort.Unix.cs} (60%) diff --git a/src/libraries/System.IO.Ports/pkg/System.IO.Ports.pkgproj b/src/libraries/System.IO.Ports/pkg/System.IO.Ports.pkgproj index 1344260b32760..d100db7d9a7e4 100644 --- a/src/libraries/System.IO.Ports/pkg/System.IO.Ports.pkgproj +++ b/src/libraries/System.IO.Ports/pkg/System.IO.Ports.pkgproj @@ -5,6 +5,7 @@ net461;netcoreapp2.0;uap10.0.16299;$(AllXamarinFrameworks) + diff --git a/src/libraries/System.IO.Ports/ref/System.IO.Ports.csproj b/src/libraries/System.IO.Ports/ref/System.IO.Ports.csproj index 85b352191c9c8..c6278c5404322 100644 --- a/src/libraries/System.IO.Ports/ref/System.IO.Ports.csproj +++ b/src/libraries/System.IO.Ports/ref/System.IO.Ports.csproj @@ -1,9 +1,14 @@ - netstandard2.0;net461 + $(NetCoreAppCurrent);netstandard2.0;net461 + + + + + \ No newline at end of file diff --git a/src/libraries/System.IO.Ports/src/System.IO.Ports.csproj b/src/libraries/System.IO.Ports/src/System.IO.Ports.csproj index 878c5e2a3f988..c3691c1b93381 100644 --- a/src/libraries/System.IO.Ports/src/System.IO.Ports.csproj +++ b/src/libraries/System.IO.Ports/src/System.IO.Ports.csproj @@ -1,17 +1,18 @@ true - $(DefineConstants);NOSPAN;SERIAL_PORTS + $(DefineConstants);SERIAL_PORTS true annotations - netstandard2.0-windows;netstandard2.0-Linux;netstandard2.0-OSX;netstandard2.0-FreeBSD;netstandard2.0;net461-windows + $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent);netstandard2.0-windows;netstandard2.0-Unix;netstandard2.0;net461-windows + true SR.PlatformNotSupported_IOPorts - true + @@ -29,6 +30,7 @@ + - - - - - - - - - - + + + @@ -133,6 +128,25 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.FreeBSD.cs b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.FreeBSD.cs deleted file mode 100644 index 10ddfa521d5a9..0000000000000 --- a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.FreeBSD.cs +++ /dev/null @@ -1,36 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.ComponentModel; -using System.Collections.Generic; -using System.IO; - -namespace System.IO.Ports -{ - public partial class SerialPort : Component - { - public static string[] GetPortNames() - { - List ports = new List(); - - foreach (string name in Directory.GetFiles("/dev", "ttyd*")) - { - if (!name.EndsWith(".init", StringComparison.Ordinal) && !name.EndsWith(".lock", StringComparison.Ordinal)) - { - ports.Add(name); - } - } - - foreach (string name in Directory.GetFiles("/dev", "cuau*")) - { - if (!name.EndsWith(".init", StringComparison.Ordinal) && !name.EndsWith(".lock", StringComparison.Ordinal)) - { - ports.Add(name); - } - } - - return ports.ToArray(); - } - } -} diff --git a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.OSX.cs b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.OSX.cs deleted file mode 100644 index c3077c339bf6f..0000000000000 --- a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.OSX.cs +++ /dev/null @@ -1,38 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.ComponentModel; -using System.Collections.Generic; -using System.IO; - -namespace System.IO.Ports -{ - public partial class SerialPort : Component - { - public static string[] GetPortNames() - { - List ports = new List(); - - foreach (string name in Directory.GetFiles("/dev", "tty.*")) - { - // GetFiles can return unexpected results because of 8.3 matching. - // Like /dev/tty - if (name.StartsWith("/dev/tty.", StringComparison.Ordinal)) - { - ports.Add(name); - } - } - - foreach (string name in Directory.GetFiles("/dev", "cu.*")) - { - if (name.StartsWith("/dev/cu.", StringComparison.Ordinal)) - { - ports.Add(name); - } - } - - return ports.ToArray(); - } - } -} diff --git a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.Linux.cs b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.Unix.cs similarity index 60% rename from src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.Linux.cs rename to src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.Unix.cs index f922ad091b1d8..e41fe33d72b82 100644 --- a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.Linux.cs +++ b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.Unix.cs @@ -5,12 +5,33 @@ using System.ComponentModel; using System.Collections.Generic; using System.IO; +using System.Runtime.InteropServices; namespace System.IO.Ports { public partial class SerialPort : Component { public static string[] GetPortNames() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return GetPortNames_Linux(); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + return GetPortNames_OSX(); + } +#if NETCOREAPP + else if (RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD)) + { + return GetPortNames_FreeBSD(); + } +#endif + + throw new PlatformNotSupportedException(SR.PlatformNotSupported_SerialPort_GetPortNames); + } + + private static string[] GetPortNames_Linux() { const string sysTtyDir = "/sys/class/tty"; const string sysUsbDir = "/sys/bus/usb-serial/devices/"; @@ -70,5 +91,55 @@ public static string[] GetPortNames() return ports.ToArray(); } } + + private static string[] GetPortNames_OSX() + { + List ports = new List(); + + foreach (string name in Directory.GetFiles("/dev", "tty.*")) + { + // GetFiles can return unexpected results because of 8.3 matching. + // Like /dev/tty + if (name.StartsWith("/dev/tty.", StringComparison.Ordinal)) + { + ports.Add(name); + } + } + + foreach (string name in Directory.GetFiles("/dev", "cu.*")) + { + if (name.StartsWith("/dev/cu.", StringComparison.Ordinal)) + { + ports.Add(name); + } + } + + return ports.ToArray(); + } + +#if NETCOREAPP + private static string[] GetPortNames_FreeBSD() + { + List ports = new List(); + + foreach (string name in Directory.GetFiles("/dev", "ttyd*")) + { + if (!name.EndsWith(".init", StringComparison.Ordinal) && !name.EndsWith(".lock", StringComparison.Ordinal)) + { + ports.Add(name); + } + } + + foreach (string name in Directory.GetFiles("/dev", "cuau*")) + { + if (!name.EndsWith(".init", StringComparison.Ordinal) && !name.EndsWith(".lock", StringComparison.Ordinal)) + { + ports.Add(name); + } + } + + return ports.ToArray(); + } +#endif } } diff --git a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.Win32.cs b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.Win32.cs index ac930c78a1a1d..22d6a92cd4bac 100644 --- a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.Win32.cs +++ b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.Win32.cs @@ -19,10 +19,6 @@ public static string[] GetPortNames() // // QueryDosDevice involves finding any ports that map to \Device\Serialx (call with null to get all, then iterate to get the actual device name) -#if NETSTANDARD - Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); -#endif - using (RegistryKey serialKey = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DEVICEMAP\SERIALCOMM")) { if (serialKey != null) diff --git a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs index e9f813fdbe05d..67ab481321550 100644 --- a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs +++ b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs @@ -431,7 +431,7 @@ public override Task ReadAsync(byte[] array, int offset, int count, Cancell return Task.FromResult(0); // return immediately if no bytes requested; no need for overhead. Memory buffer = new Memory(array, offset, count); - SerialStreamIORequest result = new SerialStreamIORequest(cancellationToken, buffer); + SerialStreamIORequest result = new(cancellationToken, buffer); _readQueue.Enqueue(result); EnsureIOLoopRunning(); @@ -439,6 +439,18 @@ public override Task ReadAsync(byte[] array, int offset, int count, Cancell return result.Task; } +#if NETCOREAPP + public override ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default) + { + SerialStreamIORequest result = new(cancellationToken, buffer); + _readQueue.Enqueue(result); + + EnsureIOLoopRunning(); + + return new ValueTask(result.Task); + } +#endif + public override Task WriteAsync(byte[] array, int offset, int count, CancellationToken cancellationToken) { CheckWriteArguments(array, offset, count); @@ -447,7 +459,7 @@ public override Task WriteAsync(byte[] array, int offset, int count, Cancellatio return Task.CompletedTask; // return immediately if no bytes to write; no need for overhead. Memory buffer = new Memory(array, offset, count); - SerialStreamIORequest result = new SerialStreamIORequest(cancellationToken, buffer); + SerialStreamIORequest result = new(cancellationToken, buffer); _writeQueue.Enqueue(result); EnsureIOLoopRunning(); @@ -455,6 +467,18 @@ public override Task WriteAsync(byte[] array, int offset, int count, Cancellatio return result.Task; } +#if NETCOREAPP + public override ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default) + { + SerialStreamIORequest result = new(cancellationToken, buffer); + _writeQueue.Enqueue(result); + + EnsureIOLoopRunning(); + + return new ValueTask(result.Task); + } +#endif + public override IAsyncResult BeginRead(byte[] array, int offset, int numBytes, AsyncCallback userCallback, object stateObject) { return TaskToApm.Begin(ReadAsync(array, offset, numBytes), userCallback, stateObject); @@ -715,7 +739,7 @@ private void RaiseDataReceivedEof() private unsafe int ProcessRead(SerialStreamIORequest r) { - Span buff = r.Buffer.Span; + ReadOnlySpan buff = r.Buffer.Span; fixed (byte* bufPtr = buff) { // assumes dequeue-ing happens on a single thread @@ -964,11 +988,11 @@ private static Exception GetLastIOError() private sealed class SerialStreamIORequest : TaskCompletionSource { - public Memory Buffer { get; private set; } + public ReadOnlyMemory Buffer { get; private set; } public bool IsCompleted => Task.IsCompleted; private CancellationToken _cancellationToken; - public SerialStreamIORequest(CancellationToken ct, Memory buffer) + public SerialStreamIORequest(CancellationToken ct, ReadOnlyMemory buffer) : base(TaskCreationOptions.RunContinuationsAsynchronously) { _cancellationToken = ct; From 39d13198fb79f2969b93c3ecad913abeefdc30c2 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Tue, 22 Jun 2021 21:26:26 +0200 Subject: [PATCH 08/25] Add NetCoreAppCurrent to System.Data.OleDb --- .../pkg/System.Data.OleDb.pkgproj | 1 + .../ref/System.Data.OleDb.cs | 4 +- .../ref/System.Data.OleDb.csproj | 11 +++-- .../System.Data.OleDb/src/ColumnBinding.cs | 10 ++++ .../src/DbConnectionOptions.cs | 39 +++++++++++++++- .../System.Data.OleDb/src/DbPropSet.cs | 9 +++- .../System.Data.OleDb/src/OleDbCommand.cs | 8 +++- .../src/OleDbConnectionString.cs | 4 ++ .../System.Data.OleDb/src/OleDbDataAdapter.cs | 2 +- .../System.Data.OleDb/src/OleDbDataReader.cs | 14 ++++-- .../src/OleDbMetaDataFactory.cs | 4 +- .../System.Data.OleDb/src/OleDbTransaction.cs | 12 ++++- .../System.Data.OleDb/src/OleDbWrapper.cs | 10 ++++ .../System.Data.OleDb/src/PropertyInfoSet.cs | 4 ++ .../System.Data.OleDb/src/RowBinding.cs | 34 +++++++++++--- .../System.Data.OleDb/src/SafeHandles.cs | 8 ++++ .../src/System.Data.OleDb.csproj | 46 ++++++++++++++++--- .../src/System/Data/Common/AdapterUtil.cs | 4 ++ .../src/System/Data/ProviderBase/DbBuffer.cs | 42 +++++++++++++++++ .../Data/ProviderBase/DbConnectionPool.cs | 24 ++++++++-- .../Data/ProviderBase/DbMetaDataFactory.cs | 12 ++--- .../Data/ProviderBase/WrappedIUnknown.cs | 4 ++ 22 files changed, 263 insertions(+), 43 deletions(-) diff --git a/src/libraries/System.Data.OleDb/pkg/System.Data.OleDb.pkgproj b/src/libraries/System.Data.OleDb/pkg/System.Data.OleDb.pkgproj index 363d30827ca3e..1f5f6789ca9e0 100644 --- a/src/libraries/System.Data.OleDb/pkg/System.Data.OleDb.pkgproj +++ b/src/libraries/System.Data.OleDb/pkg/System.Data.OleDb.pkgproj @@ -5,6 +5,7 @@ net461;netcoreapp2.0;uap10.0.16299;$(AllXamarinFrameworks) + \ No newline at end of file diff --git a/src/libraries/System.Data.OleDb/ref/System.Data.OleDb.cs b/src/libraries/System.Data.OleDb/ref/System.Data.OleDb.cs index 9011a9f247d13..a29a00d7a6af5 100644 --- a/src/libraries/System.Data.OleDb/ref/System.Data.OleDb.cs +++ b/src/libraries/System.Data.OleDb/ref/System.Data.OleDb.cs @@ -179,7 +179,7 @@ public event System.Data.OleDb.OleDbRowUpdatingEventHandler? RowUpdating { add { public int Fill(System.Data.DataTable dataTable, object ADODBRecordSet) { throw null; } protected override void OnRowUpdated(System.Data.Common.RowUpdatedEventArgs value) { } protected override void OnRowUpdating(System.Data.Common.RowUpdatingEventArgs value) { } - object? System.ICloneable.Clone() { throw null; } + object System.ICloneable.Clone() { throw null; } } public sealed partial class OleDbDataReader : System.Data.Common.DbDataReader { @@ -363,7 +363,7 @@ public OleDbParameter(string? name, object? value) { } public override object? Value { get { throw null; } set { } } public override void ResetDbType() { } public void ResetOleDbType() { } - object? System.ICloneable.Clone() { throw null; } + object System.ICloneable.Clone() { throw null; } public override string ToString() { throw null; } } [System.ComponentModel.EditorAttribute("Microsoft.VSDesigner.Data.Design.DBParametersEditor, Microsoft.VSDesigner, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] diff --git a/src/libraries/System.Data.OleDb/ref/System.Data.OleDb.csproj b/src/libraries/System.Data.OleDb/ref/System.Data.OleDb.csproj index b7a09b249da42..a08c83b5cc146 100644 --- a/src/libraries/System.Data.OleDb/ref/System.Data.OleDb.csproj +++ b/src/libraries/System.Data.OleDb/ref/System.Data.OleDb.csproj @@ -1,20 +1,24 @@ - netstandard2.0;net461 + $(NetCoreAppCurrent);netstandard2.0;net461 $(NoWarn);0618 enable + + - - + + + + @@ -22,5 +26,6 @@ + \ No newline at end of file diff --git a/src/libraries/System.Data.OleDb/src/ColumnBinding.cs b/src/libraries/System.Data.OleDb/src/ColumnBinding.cs index 8eca4d6280676..9f7c87a728048 100644 --- a/src/libraries/System.Data.OleDb/src/ColumnBinding.cs +++ b/src/libraries/System.Data.OleDb/src/ColumnBinding.cs @@ -631,7 +631,9 @@ private string Value_BSTR() string value = ""; RowBinding bindings = RowBinding; bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { bindings.DangerousAddRef(ref mustRelease); @@ -666,7 +668,9 @@ private byte[] Value_ByRefBYTES() byte[]? value = null; RowBinding bindings = RowBinding; bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { bindings.DangerousAddRef(ref mustRelease); @@ -714,7 +718,9 @@ private string Value_ByRefWSTR() string value = ""; RowBinding bindings = RowBinding; bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { bindings.DangerousAddRef(ref mustRelease); @@ -1015,7 +1021,9 @@ private object Value_IDISPATCH() object value; RowBinding bindings = RowBinding; bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { bindings.DangerousAddRef(ref mustRelease); @@ -1062,7 +1070,9 @@ private object Value_IUNKNOWN() object value; RowBinding bindings = RowBinding; bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { bindings.DangerousAddRef(ref mustRelease); diff --git a/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs b/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs index 2d47d32c4d9f2..53e31f09c3b34 100644 --- a/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs +++ b/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs @@ -228,7 +228,11 @@ internal static void AppendKeyValuePairBuilder(StringBuilder builder, string key // -> builder.Append(keyValue); } +#if NETCOREAPP + else if (keyValue.Contains('\"') && !keyValue.Contains('\'')) +#else else if ((-1 != keyValue.IndexOf('\"')) && (-1 == keyValue.IndexOf('\''))) +#endif { // -> <'val"ue'> builder.Append('\''); @@ -367,17 +371,29 @@ protected internal virtual string Expand() if (!rootFolderEndsWith && !fileNameStartsWith) { // need to insert '\' +#if NETCOREAPP + fullPath = string.Concat(rootFolderPath + '\\', value.AsSpan(fileNamePosition)); +#else fullPath = rootFolderPath + '\\' + value.Substring(fileNamePosition); +#endif } else if (rootFolderEndsWith && fileNameStartsWith) { // need to strip one out +#if NETCOREAPP + fullPath = string.Concat(rootFolderPath, value.AsSpan(fileNamePosition + 1)); +#else fullPath = rootFolderPath + value.Substring(fileNamePosition + 1); +#endif } else { // simply concatenate the strings +#if NETCOREAPP + fullPath = string.Concat(rootFolderPath, value.AsSpan(fileNamePosition)); +#else fullPath = rootFolderPath + value.Substring(fileNamePosition); +#endif } // verify root folder path is a real path without unexpected "..\" @@ -754,9 +770,17 @@ private static bool IsValueValidInternal(string? keyvalue) { #if DEBUG bool compValue = ConnectionStringValidValueRegex.IsMatch(keyvalue); +#if NETCOREAPP + Debug.Assert(!keyvalue.Contains('\u0000') == compValue, "IsValueValid mismatch with regex"); +#else Debug.Assert((-1 == keyvalue.IndexOf('\u0000')) == compValue, "IsValueValid mismatch with regex"); #endif +#endif +#if NETCOREAPP + return !keyvalue.Contains('\u0000'); +#else return (-1 == keyvalue.IndexOf('\u0000')); +#endif } return true; } @@ -767,9 +791,20 @@ private static bool IsKeyNameValid([NotNullWhen(true)] string? keyname) { #if DEBUG bool compValue = ConnectionStringValidKeyRegex.IsMatch(keyname); - Debug.Assert(((0 < keyname.Length) && (';' != keyname[0]) && !char.IsWhiteSpace(keyname[0]) && (-1 == keyname.IndexOf('\u0000'))) == compValue, "IsValueValid mismatch with regex"); + Debug.Assert(((0 < keyname.Length) && (';' != keyname[0]) && !char.IsWhiteSpace(keyname[0]) && +#if NETCOREAPP + !keyname.Contains('\u0000') +#else + (-1 == keyname.IndexOf('\u0000')) +#endif + ) == compValue, "IsValueValid mismatch with regex"); +#endif + return ((0 < keyname.Length) && (';' != keyname[0]) && !char.IsWhiteSpace(keyname[0]) && +#if NETCOREAPP + !keyname.Contains('\u0000')); +#else + (-1 == keyname.IndexOf('\u0000'))); #endif - return ((0 < keyname.Length) && (';' != keyname[0]) && !char.IsWhiteSpace(keyname[0]) && (-1 == keyname.IndexOf('\u0000'))); } return false; } diff --git a/src/libraries/System.Data.OleDb/src/DbPropSet.cs b/src/libraries/System.Data.OleDb/src/DbPropSet.cs index 756c4612c3f1f..10681aeca4440 100644 --- a/src/libraries/System.Data.OleDb/src/DbPropSet.cs +++ b/src/libraries/System.Data.OleDb/src/DbPropSet.cs @@ -25,10 +25,12 @@ internal DBPropSet(int propertysetCount) : this() { this.propertySetCount = propertysetCount; IntPtr countOfBytes = (IntPtr)(propertysetCount * ODB.SizeOf_tagDBPROPSET); +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally +#endif { base.handle = SafeNativeMethods.CoTaskMemAlloc(countOfBytes); if (ADP.PtrZero != base.handle) @@ -175,7 +177,9 @@ internal ItagDBPROP[] GetPropertySet(int index, out Guid propertyset) ItagDBPROP[]? properties = null; bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -223,17 +227,20 @@ internal void SetPropertySet(int index, Guid propertySet, ItagDBPROP[] propertie tagDBPROPSET propset = new tagDBPROPSET(properties.Length, propertySet); bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); IntPtr propsetPtr = ADP.IntPtrOffset(DangerousGetHandle(), index * ODB.SizeOf_tagDBPROPSET); - +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally +#endif { // must allocate and clear the memory without interruption propset.rgProperties = SafeNativeMethods.CoTaskMemAlloc(countOfBytes); diff --git a/src/libraries/System.Data.OleDb/src/OleDbCommand.cs b/src/libraries/System.Data.OleDb/src/OleDbCommand.cs index a6b9503e0abf6..39b2c638d143e 100644 --- a/src/libraries/System.Data.OleDb/src/OleDbCommand.cs +++ b/src/libraries/System.Data.OleDb/src/OleDbCommand.cs @@ -814,8 +814,9 @@ private int ExecuteCommandText(out object executeResult) RowBinding? rowbinding = null; Bindings? bindings = ParameterBindings; bool mustRelease = false; - +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { if (null != bindings) @@ -971,8 +972,9 @@ private int ExecuteTableDirect(CommandBehavior behavior, out object? executeResu StringMemHandle? sptr = null; bool mustReleaseStringHandle = false; - +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { sptr = new StringMemHandle(ExpandCommandText()); @@ -993,7 +995,9 @@ private int ExecuteTableDirect(CommandBehavior behavior, out object? executeResu if (null != propSet) { bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { propSet.DangerousAddRef(ref mustRelease); diff --git a/src/libraries/System.Data.OleDb/src/OleDbConnectionString.cs b/src/libraries/System.Data.OleDb/src/OleDbConnectionString.cs index e31ff207c5709..4ecaa7e29fcdd 100644 --- a/src/libraries/System.Data.OleDb/src/OleDbConnectionString.cs +++ b/src/libraries/System.Data.OleDb/src/OleDbConnectionString.cs @@ -112,7 +112,11 @@ internal OleDbConnectionString(string connectionString, bool validate) : base(co if (!ADP.IsEmpty(udlConnectionString)) { +#if NETCOREAPP + _expandedConnectionString = string.Concat(_expandedConnectionString!.AsSpan(0, position), udlConnectionString + ';', _expandedConnectionString.AsSpan(position)); +#else _expandedConnectionString = _expandedConnectionString!.Substring(0, position) + udlConnectionString + ';' + _expandedConnectionString.Substring(position); +#endif } } } diff --git a/src/libraries/System.Data.OleDb/src/OleDbDataAdapter.cs b/src/libraries/System.Data.OleDb/src/OleDbDataAdapter.cs index a9aa7d1d56b33..9c6fb06c90101 100644 --- a/src/libraries/System.Data.OleDb/src/OleDbDataAdapter.cs +++ b/src/libraries/System.Data.OleDb/src/OleDbDataAdapter.cs @@ -117,7 +117,7 @@ public event OleDbRowUpdatingEventHandler? RowUpdating // prevent someone from registering two different command builders on the adapter by // silently removing the old one - if ((null != handler) && (value.Target is DbCommandBuilder)) + if ((null != handler) && (value!.Target is DbCommandBuilder)) { OleDbRowUpdatingEventHandler? d = (OleDbRowUpdatingEventHandler?)ADP.FindBuilder(handler); if (null != d) diff --git a/src/libraries/System.Data.OleDb/src/OleDbDataReader.cs b/src/libraries/System.Data.OleDb/src/OleDbDataReader.cs index f3b6a0e011710..da1d2cb6988d6 100644 --- a/src/libraries/System.Data.OleDb/src/OleDbDataReader.cs +++ b/src/libraries/System.Data.OleDb/src/OleDbDataReader.cs @@ -968,7 +968,7 @@ private OleDbDataReader GetDataForReader(IntPtr ordinal, RowBinding rowbinding, OleDbDataReader? reader = null; - if (null != result) + if (result != null) { // only when the first datareader is closed will the connection close ChapterHandle chapterHandle = ChapterHandle.CreateChapterHandle(result, rowbinding, valueOffset); @@ -977,7 +977,7 @@ private OleDbDataReader GetDataForReader(IntPtr ordinal, RowBinding rowbinding, reader.BuildMetaInfo(); reader.HasRowsRead(); - if (null != _connection) + if (_connection != null) { // connection tracks all readers to prevent cmd from executing // until all readers (including nested) are closed @@ -985,7 +985,7 @@ private OleDbDataReader GetDataForReader(IntPtr ordinal, RowBinding rowbinding, } } - return reader; + return reader!; } public override string GetDataTypeName(int index) @@ -1730,8 +1730,9 @@ private void GetRowHandles(/*int skipCount*/) RowHandleBuffer rowHandleBuffer = _rowHandleNativeBuffer!; bool mustRelease = false; - +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { rowHandleBuffer.DangerousAddRef(ref mustRelease); @@ -1786,7 +1787,9 @@ private void GetRowDataFromHandle() IntPtr accessorHandle = rowBinding.DangerousGetAccessorHandle(); bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { rowBinding.DangerousAddRef(ref mustRelease); @@ -1881,8 +1884,9 @@ private void GetRowValue() bool mustReleaseBinding = false; bool[] mustRelease = new bool[columnBindings.Length]; StringMemHandle?[] sptr = new StringMemHandle[columnBindings.Length]; - +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { for (int i = 0; i < columnBindings.Length; ++i) diff --git a/src/libraries/System.Data.OleDb/src/OleDbMetaDataFactory.cs b/src/libraries/System.Data.OleDb/src/OleDbMetaDataFactory.cs index e978419c2f836..d2620c38b1c53 100644 --- a/src/libraries/System.Data.OleDb/src/OleDbMetaDataFactory.cs +++ b/src/libraries/System.Data.OleDb/src/OleDbMetaDataFactory.cs @@ -214,13 +214,13 @@ private DataTable GetDataSourceInformationTable(OleDbConnection connection, OleD StringBuilder compositeSeparatorPattern = new StringBuilder(); StringBuilder patternEscaped = new StringBuilder(); ADP.EscapeSpecialCharacters(catalogSeparatorPattern, patternEscaped); - compositeSeparatorPattern.Append(patternEscaped.ToString()); + compositeSeparatorPattern.Append(patternEscaped); if ((schemaSeparatorPattern != null) && (schemaSeparatorPattern != catalogSeparatorPattern)) { compositeSeparatorPattern.Append('|'); patternEscaped.Length = 0; ADP.EscapeSpecialCharacters(schemaSeparatorPattern, patternEscaped); - compositeSeparatorPattern.Append(patternEscaped.ToString()); + compositeSeparatorPattern.Append(patternEscaped); } dataSourceInformation[DbMetaDataColumnNames.CompositeIdentifierSeparatorPattern] = compositeSeparatorPattern.ToString(); } diff --git a/src/libraries/System.Data.OleDb/src/OleDbTransaction.cs b/src/libraries/System.Data.OleDb/src/OleDbTransaction.cs index 26a20357af16b..6df9c7728a164 100644 --- a/src/libraries/System.Data.OleDb/src/OleDbTransaction.cs +++ b/src/libraries/System.Data.OleDb/src/OleDbTransaction.cs @@ -26,10 +26,12 @@ private sealed class WrappedTransaction : WrappedIUnknown internal WrappedTransaction(UnsafeNativeMethods.ITransactionLocal transaction, int isolevel, out OleDbHResult hr) : base(transaction) { int transactionLevel = 0; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally +#endif { hr = transaction.StartTransaction(isolevel, 0, IntPtr.Zero, out transactionLevel); if (0 <= hr) @@ -49,14 +51,18 @@ internal OleDbHResult Abort() Debug.Assert(_mustComplete, "transaction already completed"); OleDbHResult hr; bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally +#endif { hr = (OleDbHResult)NativeOledbWrapper.ITransactionAbort(DangerousGetHandle()); _mustComplete = false; @@ -77,14 +83,18 @@ internal OleDbHResult Commit() Debug.Assert(_mustComplete, "transaction already completed"); OleDbHResult hr; bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally +#endif { hr = (OleDbHResult)NativeOledbWrapper.ITransactionCommit(DangerousGetHandle()); if ((0 <= (int)hr) || (OleDbHResult.XACT_E_NOTRANSACTION == hr)) @@ -181,7 +191,7 @@ public OleDbTransaction Begin(IsolationLevel isolevel) } else if ((null != _nestedTransaction) && _nestedTransaction.IsAlive) { - throw ADP.ParallelTransactionsNotSupported(Connection); + throw ADP.ParallelTransactionsNotSupported(Connection!); } // either the connection will be open or this will be a zombie diff --git a/src/libraries/System.Data.OleDb/src/OleDbWrapper.cs b/src/libraries/System.Data.OleDb/src/OleDbWrapper.cs index 23ef6c6b0d495..77de0cadcd8b8 100644 --- a/src/libraries/System.Data.OleDb/src/OleDbWrapper.cs +++ b/src/libraries/System.Data.OleDb/src/OleDbWrapper.cs @@ -24,10 +24,12 @@ internal OleDbServicesWrapper(object? unknown) : base() { if (null != unknown) { +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally +#endif { // store the QI result for IID_IDataInitialize base.handle = Marshal.GetComInterfaceForObject(unknown, typeof(UnsafeNativeMethods.IDataInitialize)); @@ -46,7 +48,9 @@ internal void GetDataSource(OleDbConnectionString constr, ref DataSourceWrapper OleDbHResult hr; UnsafeNativeMethods.IDataInitializeGetDataSource GetDataSource = DangerousIDataInitializeGetDataSource!; bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -101,7 +105,9 @@ internal OleDbHResult InitializeAndCreateSession(OleDbConnectionString constr, r OleDbHResult hr; bool mustRelease = false; IntPtr idbCreateSession = IntPtr.Zero; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -254,7 +260,9 @@ internal void QueryInterfaceIDBCreateCommand(OleDbConnectionString constr) if (!constr.HaveQueriedForCreateCommand || (null != constr.DangerousIDBCreateCommandCreateCommand)) { IntPtr idbCreateCommand = IntPtr.Zero; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { // native COM rules are the QI result is the 'this' pointer @@ -327,7 +335,9 @@ internal OleDbHResult CreateCommand(ref object? icommandText) if (null != CreateCommand) { bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); diff --git a/src/libraries/System.Data.OleDb/src/PropertyInfoSet.cs b/src/libraries/System.Data.OleDb/src/PropertyInfoSet.cs index 60b44bab7de48..9c36259df011f 100644 --- a/src/libraries/System.Data.OleDb/src/PropertyInfoSet.cs +++ b/src/libraries/System.Data.OleDb/src/PropertyInfoSet.cs @@ -33,10 +33,12 @@ internal PropertyInfoSet(UnsafeNativeMethods.IDBProperties idbProperties, Proper { OleDbHResult hr; int propIDSetCount = propIDSet.Count; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally +#endif { hr = idbProperties.GetPropertyInfo(propIDSetCount, propIDSet, out this.setCount, out base.handle, out this.descBuffer); } @@ -59,7 +61,9 @@ public override bool IsInvalid Dictionary? propertyLookup = null; bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); diff --git a/src/libraries/System.Data.OleDb/src/RowBinding.cs b/src/libraries/System.Data.OleDb/src/RowBinding.cs index 7f94bf563d5f1..39df330f8b485 100644 --- a/src/libraries/System.Data.OleDb/src/RowBinding.cs +++ b/src/libraries/System.Data.OleDb/src/RowBinding.cs @@ -125,8 +125,9 @@ internal ColumnBinding[] SetBindings(OleDbDataReader? dataReader, Bindings bindi Debug.Assert(dbbindings.Length == BindingCount(), "count mismatch"); bool mustRelease = false; - +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -174,7 +175,9 @@ internal object GetVariantValue(int offset) object? value = null; bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -204,14 +207,17 @@ internal void SetVariantValue(int offset, object value) IntPtr buffer = ADP.PtrZero; bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); buffer = ADP.IntPtrOffset(DangerousGetHandle(), offset); - +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { // GetNativeVariantForObject must be in try block since it has no reliability contract @@ -245,15 +251,18 @@ internal void SetBstrValue(int offset, string value) IntPtr ptr; bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); - +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally +#endif { ptr = SafeNativeMethods.SysAllocStringLen(value, value.Length); @@ -287,15 +296,18 @@ internal void SetByRefValue(int offset, IntPtr pinnedValue) pinnedValue = ADP.IntPtrOffset(base.handle, _emptyStringOffset); } bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); - +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally +#endif { Marshal.WriteIntPtr(base.handle, offset, pinnedValue); // parameter input value Marshal.WriteIntPtr(base.handle, offset + ADP.PtrSize, pinnedValue); // original parameter value @@ -348,7 +360,9 @@ internal void ResetValues() { // prevent Dispose/ResetValues race condition bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -487,10 +501,12 @@ private static void FreeBstr(IntPtr buffer, int valueOffset) // two contigous BSTR ptrs that need to be freed // the second should only be freed if different from the first +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally +#endif { IntPtr currentValue = Marshal.ReadIntPtr(buffer, valueOffset); IntPtr originalValue = Marshal.ReadIntPtr(buffer, valueOffset + ADP.PtrSize); @@ -516,10 +532,12 @@ private static void FreeCoTaskMem(IntPtr buffer, int valueOffset) // two contigous CoTaskMemAlloc ptrs that need to be freed // the first should only be freed if different from the first +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally +#endif { IntPtr currentValue = Marshal.ReadIntPtr(buffer, valueOffset); IntPtr originalValue = Marshal.ReadIntPtr(buffer, valueOffset + ADP.PtrSize); @@ -547,11 +565,12 @@ private static void FreeVariant(IntPtr buffer, int valueOffset) IntPtr currentHandle = ADP.IntPtrOffset(buffer, valueOffset); IntPtr originalHandle = ADP.IntPtrOffset(buffer, valueOffset + ODB.SizeOf_Variant); bool different = NativeOledbWrapper.MemoryCompare(currentHandle, originalHandle, ODB.SizeOf_Variant); - +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally +#endif { // always clear the first structure SafeNativeMethods.VariantClear(currentHandle); @@ -578,11 +597,12 @@ private static unsafe void FreePropVariant(IntPtr buffer, int valueOffset) IntPtr currentHandle = ADP.IntPtrOffset(buffer, valueOffset); IntPtr originalHandle = ADP.IntPtrOffset(buffer, valueOffset + sizeof(PROPVARIANT)); bool different = NativeOledbWrapper.MemoryCompare(currentHandle, originalHandle, sizeof(PROPVARIANT)); - +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally +#endif { // always clear the first structure SafeNativeMethods.PropVariantClear(currentHandle); @@ -606,7 +626,9 @@ internal IntPtr InterlockedExchangePointer(int offset) IntPtr value; bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); diff --git a/src/libraries/System.Data.OleDb/src/SafeHandles.cs b/src/libraries/System.Data.OleDb/src/SafeHandles.cs index d435f7f45bcd1..e73a42f07c6a9 100644 --- a/src/libraries/System.Data.OleDb/src/SafeHandles.cs +++ b/src/libraries/System.Data.OleDb/src/SafeHandles.cs @@ -135,10 +135,12 @@ private ChapterHandle(IntPtr chapter) : base((object?)null) private ChapterHandle(object chapteredRowset, RowBinding binding, int valueOffset) : base(chapteredRowset) { +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally +#endif { _chapterHandle = binding.InterlockedExchangePointer(valueOffset); } @@ -666,10 +668,12 @@ internal static unsafe OleDbHResult IChapteredRowsetReleaseChapter(System.IntPtr OleDbHResult hr = OleDbHResult.E_UNEXPECTED; IntPtr hchapter = chapter; System.Data.Common.UnsafeNativeMethods.IChapteredRowset? chapteredRowset = null; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally +#endif { Guid IID_IChapteredRowset = typeof(System.Data.Common.UnsafeNativeMethods.IChapteredRowset).GUID; hr = (OleDbHResult)Marshal.QueryInterface(ptr, ref IID_IChapteredRowset, out var pChapteredRowset); @@ -688,10 +692,12 @@ internal static unsafe OleDbHResult ITransactionAbort(System.IntPtr ptr) { OleDbHResult hr = OleDbHResult.E_UNEXPECTED; ITransactionLocal? transactionLocal = null; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally +#endif { Guid IID_ITransactionLocal = typeof(ITransactionLocal).GUID; hr = (OleDbHResult)Marshal.QueryInterface(ptr, ref IID_ITransactionLocal, out var pTransaction); @@ -710,10 +716,12 @@ internal static unsafe OleDbHResult ITransactionCommit(System.IntPtr ptr) { OleDbHResult hr = OleDbHResult.E_UNEXPECTED; ITransactionLocal? transactionLocal = null; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally +#endif { Guid IID_ITransactionLocal = typeof(ITransactionLocal).GUID; hr = (OleDbHResult)Marshal.QueryInterface(ptr, ref IID_ITransactionLocal, out var pTransaction); diff --git a/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj b/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj index 4140b529697a1..992d0e6b42b9f 100644 --- a/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj +++ b/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj @@ -1,16 +1,18 @@ true - netstandard2.0-windows;netstandard2.0;net461-windows + $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent);netstandard2.0-windows;netstandard2.0;net461-windows true enable + true SR.PlatformNotSupported_OleDb - $(NoWarn);CS0618 + $(NoWarn);CS0618 + @@ -91,11 +93,43 @@ + - - System.Data.OleDb.OleDbMetaData.xml - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -103,7 +137,5 @@ - - diff --git a/src/libraries/System.Data.OleDb/src/System/Data/Common/AdapterUtil.cs b/src/libraries/System.Data.OleDb/src/System/Data/Common/AdapterUtil.cs index f5bacfd623917..491033233776d 100644 --- a/src/libraries/System.Data.OleDb/src/System/Data/Common/AdapterUtil.cs +++ b/src/libraries/System.Data.OleDb/src/System/Data/Common/AdapterUtil.cs @@ -1016,7 +1016,11 @@ internal static void EscapeSpecialCharacters(string unescapedString, StringBuild foreach (char currentChar in unescapedString) { +#if NETCOREAPP + if (specialCharacters.Contains(currentChar)) +#else if (specialCharacters.IndexOf(currentChar) >= 0) +#endif { escapedString.Append('\\'); } diff --git a/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbBuffer.cs b/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbBuffer.cs index dc0db72fa5c6c..54031316fd6e1 100644 --- a/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbBuffer.cs +++ b/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbBuffer.cs @@ -25,10 +25,12 @@ private DbBuffer(int initialSize, bool zeroBuffer) : base(IntPtr.Zero, true) int flags = ((zeroBuffer) ? LMEM_ZEROINIT : LMEM_FIXED); _bufferLength = initialSize; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally +#endif { base.handle = SafeNativeMethods.LocalAlloc(flags, (IntPtr)initialSize); } @@ -73,7 +75,9 @@ internal string PtrToStringUni(int offset, int length) string? value = null; bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -99,7 +103,9 @@ internal byte ReadByte(int offset) byte value; bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -132,7 +138,9 @@ internal byte[] ReadBytes(int offset, byte[] destination, int startIndex, int le Debug.Assert(startIndex + length <= destination.Length, "destination too small"); bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -165,7 +173,9 @@ internal char[] ReadChars(int offset, char[] destination, int startIndex, int le Debug.Assert(startIndex + length <= destination.Length, "destination too small"); bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -197,7 +207,9 @@ internal short ReadInt16(int offset) short value; bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -224,7 +236,9 @@ internal void ReadInt16Array(int offset, short[] destination, int startIndex, in Debug.Assert(startIndex + length <= destination.Length, "destination too small"); bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -249,7 +263,9 @@ internal int ReadInt32(int offset) int value; bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -276,7 +292,9 @@ internal void ReadInt32Array(int offset, int[] destination, int startIndex, int Debug.Assert(startIndex + length <= destination.Length, "destination too small"); bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -301,7 +319,9 @@ internal long ReadInt64(int offset) long value; bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -327,7 +347,9 @@ internal IntPtr ReadIntPtr(int offset) IntPtr value; bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -371,7 +393,9 @@ private void StructureToPtr(int offset, object structure) Debug.Assert(0 == offset % ADP.PtrSize, "invalid alignment"); bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -395,7 +419,9 @@ internal void WriteByte(int offset, byte value) Debug.Assert(0 == offset % 4, "invalid alignment"); bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -421,7 +447,9 @@ internal void WriteBytes(int offset, byte[] source, int startIndex, int length) Debug.Assert(startIndex + length <= source.Length, "source too small"); bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -447,7 +475,9 @@ internal void WriteCharArray(int offset, char[] source, int startIndex, int leng Debug.Assert(startIndex + length <= source.Length, "source too small"); bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -476,7 +506,9 @@ internal void WriteInt16(int offset, short value) Debug.Assert(0 == offset % 2, "invalid alignment"); bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -502,7 +534,9 @@ internal void WriteInt16Array(int offset, short[] source, int startIndex, int le Debug.Assert(startIndex + length <= source.Length, "source too small"); bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -526,7 +560,9 @@ internal void WriteInt32(int offset, int value) Debug.Assert(0 == offset % 4, "invalid alignment"); bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -552,7 +588,9 @@ internal void WriteInt32Array(int offset, int[] source, int startIndex, int leng Debug.Assert(startIndex + length <= source.Length, "source too small"); bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -576,7 +614,9 @@ internal void WriteInt64(int offset, long value) Debug.Assert(0 == offset % IntPtr.Size, "invalid alignment"); bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); @@ -600,7 +640,9 @@ internal void WriteIntPtr(int offset, IntPtr value) Debug.Assert(0 == offset % IntPtr.Size, "invalid alignment"); bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); diff --git a/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbConnectionPool.cs b/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbConnectionPool.cs index e411fc550101f..4ce824be6fef4 100644 --- a/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbConnectionPool.cs +++ b/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbConnectionPool.cs @@ -240,8 +240,9 @@ internal PoolWaitHandles() : base(3 * IntPtr.Size) _poolSemaphore = new Semaphore(0, MAX_Q_SIZE); _errorEvent = new ManualResetEvent(false); _creationSemaphore = new Semaphore(1, 1); - +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { // because SafeWaitHandle doesn't have reliability contract @@ -730,10 +731,12 @@ private DbConnectionInternal CreateObject(DbConnection? owningObject, DbConnecti // timer allocation has to be done out of CER block Timer t = new Timer(new TimerCallback(this.ErrorCallback), null, Timeout.Infinite, Timeout.Infinite); bool timerIsNotDisposed; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally +#endif { _waitHandles.ErrorEvent.Set(); _errorOccurred = true; @@ -951,14 +954,17 @@ private void WaitForPendingOpen() do { bool started = false; - +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally +#endif { started = Interlocked.CompareExchange(ref _pendingOpensWaiting, 1, 0) == 0; } @@ -988,8 +994,9 @@ private void WaitForPendingOpen() DbConnectionInternal? connection = null; bool timeout = false; Exception? caughtException = null; - +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { bool allowCreate = true; @@ -1129,14 +1136,18 @@ private bool TryGetConnection(DbConnection owningObject, uint waitForMultipleObj bool mustRelease = false; int waitForMultipleObjectsExHR = 0; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { _waitHandles.DangerousAddRef(ref mustRelease); // We absolutely must have the value of waitResult set, // or we may leak the mutex in async abort cases. +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { Debug.Assert(2 == waitHandleCount || 3 == waitHandleCount, "unexpected waithandle count"); @@ -1231,7 +1242,9 @@ private bool TryGetConnection(DbConnection owningObject, uint waitForMultipleObj { if (_waitHandles.CreationSemaphore.WaitOne(unchecked((int)waitForMultipleObjectsTimeout))) { +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { obj = UserCreateRequest(owningObject, userOptions); @@ -1449,18 +1462,21 @@ private void PoolCreateRequest(object? state) bool mustRelease = false; int waitResult = BOGUS_HANDLE; uint timeout = (uint)CreationTimeout; - +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { _waitHandles.DangerousAddRef(ref mustRelease); // Obtain creation mutex so we're the only one creating objects // and we must have the wait result +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally +#endif { waitResult = SafeNativeMethods.WaitForSingleObjectEx(_waitHandles.CreationHandle.DangerousGetHandle(), timeout, false); } diff --git a/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbMetaDataFactory.cs b/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbMetaDataFactory.cs index 68892d670c3c1..f9a4d529da0f4 100644 --- a/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbMetaDataFactory.cs +++ b/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbMetaDataFactory.cs @@ -130,10 +130,6 @@ private DataTable ExecuteCommand(DataRow requestedCollectionRow, string?[]? rest DataColumn collectionNameColumn = metaDataCollectionsTable.Columns[_collectionName]!; //DataColumn restrictionNameColumn = metaDataCollectionsTable.Columns[_restrictionName]; - DataTable? resultTable = null; - DbCommand? command = null; - DataTable? schemaTable = null; - Debug.Assert(requestedCollectionRow != null); string sqlCommand = (requestedCollectionRow[populationStringColumn, DataRowVersion.Current] as string)!; int numberOfRestrictions = (int)requestedCollectionRow[numberOfRestrictionsColumn, DataRowVersion.Current]; @@ -144,10 +140,11 @@ private DataTable ExecuteCommand(DataRow requestedCollectionRow, string?[]? rest throw ADP.TooManyRestrictions(collectionName); } - command = connection.CreateCommand(); + DbCommand? command = connection.CreateCommand(); command.CommandText = sqlCommand; command.CommandTimeout = System.Math.Max(command.CommandTimeout, 180); + DataTable? resultTable = null; for (int i = 0; i < numberOfRestrictions; i++) { DbParameter restrictionParameter = command.CreateParameter(); @@ -190,8 +187,8 @@ private DataTable ExecuteCommand(DataRow requestedCollectionRow, string?[]? rest resultTable = new DataTable(collectionName); resultTable.Locale = CultureInfo.InvariantCulture; - schemaTable = reader.GetSchemaTable(); - foreach (DataRow row in schemaTable.Rows) + DataTable? schemaTable = reader.GetSchemaTable(); + foreach (DataRow row in schemaTable!.Rows) { resultTable.Columns.Add(row["ColumnName"] as string, (Type)row["DataType"]); } @@ -210,6 +207,7 @@ private DataTable ExecuteCommand(DataRow requestedCollectionRow, string?[]? rest reader = null; } } + return resultTable; } diff --git a/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/WrappedIUnknown.cs b/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/WrappedIUnknown.cs index 9b3205849d249..3f7143456aa2f 100644 --- a/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/WrappedIUnknown.cs +++ b/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/WrappedIUnknown.cs @@ -22,10 +22,12 @@ internal WrappedIUnknown(object? unknown) : this() { if (null != unknown) { +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally +#endif { base.handle = Marshal.GetIUnknownForObject(unknown); } @@ -46,7 +48,9 @@ internal object ComWrapper() // runtime in the debugger. object? value = null; bool mustRelease = false; +#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { DangerousAddRef(ref mustRelease); From 03a9157d8f9106fb753b431f47aa1a65aee1c427 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Wed, 23 Jun 2021 09:14:23 +0200 Subject: [PATCH 09/25] Add NetCoreAppCurrent to M.W32.Registry.AccessControl --- .../Microsoft.Win32.Registry.AccessControl.pkgproj | 1 + .../Microsoft.Win32.Registry.AccessControl.csproj | 11 ++++++++++- .../Microsoft.Win32.Registry.AccessControl.csproj | 13 +++++++++++-- ...rosoft.Win32.Registry.AccessControl.Tests.csproj | 3 --- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/libraries/Microsoft.Win32.Registry.AccessControl/pkg/Microsoft.Win32.Registry.AccessControl.pkgproj b/src/libraries/Microsoft.Win32.Registry.AccessControl/pkg/Microsoft.Win32.Registry.AccessControl.pkgproj index 95a5015b3ce32..6a5c8b77be00e 100644 --- a/src/libraries/Microsoft.Win32.Registry.AccessControl/pkg/Microsoft.Win32.Registry.AccessControl.pkgproj +++ b/src/libraries/Microsoft.Win32.Registry.AccessControl/pkg/Microsoft.Win32.Registry.AccessControl.pkgproj @@ -7,6 +7,7 @@ + \ No newline at end of file diff --git a/src/libraries/Microsoft.Win32.Registry.AccessControl/ref/Microsoft.Win32.Registry.AccessControl.csproj b/src/libraries/Microsoft.Win32.Registry.AccessControl/ref/Microsoft.Win32.Registry.AccessControl.csproj index c6e8d3fbf20a5..5f89098d52117 100644 --- a/src/libraries/Microsoft.Win32.Registry.AccessControl/ref/Microsoft.Win32.Registry.AccessControl.csproj +++ b/src/libraries/Microsoft.Win32.Registry.AccessControl/ref/Microsoft.Win32.Registry.AccessControl.csproj @@ -1,14 +1,23 @@ - netstandard2.0;net461 + $(NetCoreAppCurrent);netstandard2.0;net461 enable + + + + + + + + + \ No newline at end of file diff --git a/src/libraries/Microsoft.Win32.Registry.AccessControl/src/Microsoft.Win32.Registry.AccessControl.csproj b/src/libraries/Microsoft.Win32.Registry.AccessControl/src/Microsoft.Win32.Registry.AccessControl.csproj index f66a53a084091..82538c4efbae4 100644 --- a/src/libraries/Microsoft.Win32.Registry.AccessControl/src/Microsoft.Win32.Registry.AccessControl.csproj +++ b/src/libraries/Microsoft.Win32.Registry.AccessControl/src/Microsoft.Win32.Registry.AccessControl.csproj @@ -1,17 +1,26 @@ true - netstandard2.0-windows;netstandard2.0;net461-windows + $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent);netstandard2.0-windows;netstandard2.0;net461-windows enable + SR.PlatformNotSupported_RegistryAccessControl - true + true + + + + + + + + diff --git a/src/libraries/Microsoft.Win32.Registry.AccessControl/tests/Microsoft.Win32.Registry.AccessControl.Tests.csproj b/src/libraries/Microsoft.Win32.Registry.AccessControl/tests/Microsoft.Win32.Registry.AccessControl.Tests.csproj index 1752e89bc52e6..fb6e2d196998f 100644 --- a/src/libraries/Microsoft.Win32.Registry.AccessControl/tests/Microsoft.Win32.Registry.AccessControl.Tests.csproj +++ b/src/libraries/Microsoft.Win32.Registry.AccessControl/tests/Microsoft.Win32.Registry.AccessControl.Tests.csproj @@ -8,7 +8,4 @@ - - - \ No newline at end of file From bb57f13f50244761d272dbbdf4d3a2c144c9903e Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Wed, 23 Jun 2021 09:31:39 +0200 Subject: [PATCH 10/25] Add NetCoreAppCurrent to S.Reflection.Context --- .../pkg/System.Reflection.Context.pkgproj | 1 + .../ref/System.Reflection.Context.csproj | 7 ++++++- .../src/System.Reflection.Context.csproj | 18 ++++++++++++++---- .../Context/Delegation/DelegatingAssembly.cs | 13 +++++++++++++ 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/libraries/System.Reflection.Context/pkg/System.Reflection.Context.pkgproj b/src/libraries/System.Reflection.Context/pkg/System.Reflection.Context.pkgproj index 29115a97cc5a9..a3234c9206913 100644 --- a/src/libraries/System.Reflection.Context/pkg/System.Reflection.Context.pkgproj +++ b/src/libraries/System.Reflection.Context/pkg/System.Reflection.Context.pkgproj @@ -19,6 +19,7 @@ + diff --git a/src/libraries/System.Reflection.Context/ref/System.Reflection.Context.csproj b/src/libraries/System.Reflection.Context/ref/System.Reflection.Context.csproj index 077aa393f180a..39d6843b59f20 100644 --- a/src/libraries/System.Reflection.Context/ref/System.Reflection.Context.csproj +++ b/src/libraries/System.Reflection.Context/ref/System.Reflection.Context.csproj @@ -4,10 +4,15 @@ plan on shipping a new desktop version out of band. Instead add API to a different assembly. --> 4.0.0.0 - netstandard2.0 + $(NetCoreAppCurrent);netstandard2.0 enable + + + + + \ No newline at end of file diff --git a/src/libraries/System.Reflection.Context/src/System.Reflection.Context.csproj b/src/libraries/System.Reflection.Context/src/System.Reflection.Context.csproj index dcbd6df8556d2..d4270565e9352 100644 --- a/src/libraries/System.Reflection.Context/src/System.Reflection.Context.csproj +++ b/src/libraries/System.Reflection.Context/src/System.Reflection.Context.csproj @@ -1,13 +1,17 @@ - netstandard2.1;netstandard2.0 + $(NetCoreAppCurrent);netstandard2.1;netstandard2.0 enable + - SR.PlatformNotSupported_ReflectionContext + + annotations + SR.PlatformNotSupported_ReflectionContext - + + @@ -63,6 +67,12 @@ - + + + + + + diff --git a/src/libraries/System.Reflection.Context/src/System/Reflection/Context/Delegation/DelegatingAssembly.cs b/src/libraries/System.Reflection.Context/src/System/Reflection/Context/Delegation/DelegatingAssembly.cs index 64c98012957c7..8fa2a434924d9 100644 --- a/src/libraries/System.Reflection.Context/src/System/Reflection/Context/Delegation/DelegatingAssembly.cs +++ b/src/libraries/System.Reflection.Context/src/System/Reflection/Context/Delegation/DelegatingAssembly.cs @@ -70,10 +70,15 @@ public override SecurityRuleSet SecurityRuleSet get { return UnderlyingAssembly.SecurityRuleSet; } } +#if NETCOREAPP + [Obsolete] +#endif +#pragma warning disable IL3002 // Using member which has 'RequiresAssemblyFilesAttribute' can break functionality when embedded in a single-file app public override string CodeBase { get { return UnderlyingAssembly.CodeBase; } } +#pragma warning restore IL3002 public override object CreateInstance(string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes) { @@ -85,10 +90,15 @@ public override MethodInfo EntryPoint get { return UnderlyingAssembly.EntryPoint; } } +#if NETCOREAPP + [Obsolete] +#endif +#pragma warning disable IL3002 // Using member which has 'RequiresAssemblyFilesAttribute' can break functionality when embedded in a single-file app public override string EscapedCodeBase { get { return UnderlyingAssembly.EscapedCodeBase; } } +#pragma warning restore IL3002 public override string FullName { @@ -188,6 +198,9 @@ public override Type[] GetTypes() return UnderlyingAssembly.GetTypes(); } +#if NETCOREAPP + [Obsolete] +#endif public override bool GlobalAssemblyCache { get { return UnderlyingAssembly.GlobalAssemblyCache; } From 69a5de2aac2b004149e75dd08e2f04011a82e50d Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Wed, 23 Jun 2021 09:36:52 +0200 Subject: [PATCH 11/25] Add NetCoreAppCurrent to S.C.Composition.Registration --- ...m.ComponentModel.Composition.Registration.pkgproj | 1 + ...em.ComponentModel.Composition.Registration.csproj | 8 +++++--- ...em.ComponentModel.Composition.Registration.csproj | 12 +++++++++++- ...ponentModel.Composition.Registration.Tests.csproj | 1 + 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.ComponentModel.Composition.Registration/pkg/System.ComponentModel.Composition.Registration.pkgproj b/src/libraries/System.ComponentModel.Composition.Registration/pkg/System.ComponentModel.Composition.Registration.pkgproj index 2ef483eed7239..4c1d0b707154a 100644 --- a/src/libraries/System.ComponentModel.Composition.Registration/pkg/System.ComponentModel.Composition.Registration.pkgproj +++ b/src/libraries/System.ComponentModel.Composition.Registration/pkg/System.ComponentModel.Composition.Registration.pkgproj @@ -9,6 +9,7 @@ true + diff --git a/src/libraries/System.ComponentModel.Composition.Registration/ref/System.ComponentModel.Composition.Registration.csproj b/src/libraries/System.ComponentModel.Composition.Registration/ref/System.ComponentModel.Composition.Registration.csproj index d99d4ac486fba..c92f8b2348972 100644 --- a/src/libraries/System.ComponentModel.Composition.Registration/ref/System.ComponentModel.Composition.Registration.csproj +++ b/src/libraries/System.ComponentModel.Composition.Registration/ref/System.ComponentModel.Composition.Registration.csproj @@ -1,12 +1,14 @@ - netstandard2.1 + $(NetCoreAppCurrent);netstandard2.1 + + - - + + \ No newline at end of file diff --git a/src/libraries/System.ComponentModel.Composition.Registration/src/System.ComponentModel.Composition.Registration.csproj b/src/libraries/System.ComponentModel.Composition.Registration/src/System.ComponentModel.Composition.Registration.csproj index cabd1dda2f242..1e12a946d7927 100644 --- a/src/libraries/System.ComponentModel.Composition.Registration/src/System.ComponentModel.Composition.Registration.csproj +++ b/src/libraries/System.ComponentModel.Composition.Registration/src/System.ComponentModel.Composition.Registration.csproj @@ -1,8 +1,9 @@ - netstandard2.1 + $(NetCoreAppCurrent);netstandard2.1 false + @@ -24,8 +25,17 @@ + + + + + + + + + diff --git a/src/libraries/System.ComponentModel.Composition.Registration/tests/System.ComponentModel.Composition.Registration.Tests.csproj b/src/libraries/System.ComponentModel.Composition.Registration/tests/System.ComponentModel.Composition.Registration.Tests.csproj index d079de0a2b670..df43866bc98e5 100644 --- a/src/libraries/System.ComponentModel.Composition.Registration/tests/System.ComponentModel.Composition.Registration.Tests.csproj +++ b/src/libraries/System.ComponentModel.Composition.Registration/tests/System.ComponentModel.Composition.Registration.Tests.csproj @@ -1,6 +1,7 @@ $(NetCoreAppCurrent) + disable From bf78da88548997e23a3423fdb6d1df77a6c7c922 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Wed, 23 Jun 2021 09:59:20 +0200 Subject: [PATCH 12/25] Add NetCoreAppCurrent to S.Resources.Extensions --- .../src/System/IO/PinnedBufferMemoryStream.cs | 2 +- .../pkg/System.Resources.Extensions.pkgproj | 1 + .../ref/System.Resources.Extensions.csproj | 7 ++++++- .../src/System.Resources.Extensions.csproj | 18 ++++++++++++++++-- .../Extensions/DeserializingResourceReader.cs | 5 +++-- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/PinnedBufferMemoryStream.cs b/src/libraries/System.Private.CoreLib/src/System/IO/PinnedBufferMemoryStream.cs index 6adab80d3efac..6a980d9fe1103 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/PinnedBufferMemoryStream.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/PinnedBufferMemoryStream.cs @@ -36,7 +36,7 @@ internal PinnedBufferMemoryStream(byte[] array) Initialize(ptr, len, len, FileAccess.Read); } -#if (!NETSTANDARD2_0 && !NETFRAMEWORK) +#if !RESOURCES_EXTENSIONS public override int Read(Span buffer) => ReadCore(buffer); public override void Write(ReadOnlySpan buffer) => WriteCore(buffer); diff --git a/src/libraries/System.Resources.Extensions/pkg/System.Resources.Extensions.pkgproj b/src/libraries/System.Resources.Extensions/pkg/System.Resources.Extensions.pkgproj index 3ac0955a841c2..68f6238d74375 100644 --- a/src/libraries/System.Resources.Extensions/pkg/System.Resources.Extensions.pkgproj +++ b/src/libraries/System.Resources.Extensions/pkg/System.Resources.Extensions.pkgproj @@ -4,6 +4,7 @@ uap10.0.16299;net461;netcoreapp2.0;$(AllXamarinFrameworks) + \ No newline at end of file diff --git a/src/libraries/System.Resources.Extensions/ref/System.Resources.Extensions.csproj b/src/libraries/System.Resources.Extensions/ref/System.Resources.Extensions.csproj index 184133af2fab9..99037ae459c92 100644 --- a/src/libraries/System.Resources.Extensions/ref/System.Resources.Extensions.csproj +++ b/src/libraries/System.Resources.Extensions/ref/System.Resources.Extensions.csproj @@ -1,9 +1,14 @@ - netstandard2.0;net461 + $(NetCoreAppCurrent);netstandard2.0;net461 enable + + + + + \ No newline at end of file diff --git a/src/libraries/System.Resources.Extensions/src/System.Resources.Extensions.csproj b/src/libraries/System.Resources.Extensions/src/System.Resources.Extensions.csproj index 2787ad7bb9598..adacc9b977e5b 100644 --- a/src/libraries/System.Resources.Extensions/src/System.Resources.Extensions.csproj +++ b/src/libraries/System.Resources.Extensions/src/System.Resources.Extensions.csproj @@ -1,10 +1,11 @@ true - netstandard2.0;net461 + $(NetCoreAppCurrent);netstandard2.0;net461 $(DefineConstants);RESOURCES_EXTENSIONS enable + @@ -26,13 +27,26 @@ + + + - + + + + + + + + + + + diff --git a/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/DeserializingResourceReader.cs b/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/DeserializingResourceReader.cs index ea9fbb4410376..ef40926e32aac 100644 --- a/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/DeserializingResourceReader.cs +++ b/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/DeserializingResourceReader.cs @@ -33,7 +33,8 @@ private bool ValidateReaderType(string readerType) return false; } - // Issue https://github.com/dotnet/runtime/issues/39292 tracks finding an alternative to BinaryFormatter +// Issue https://github.com/dotnet/runtime/issues/39292 tracks finding an alternative to BinaryFormatter +#pragma warning disable SYSLIB0011 private object ReadBinaryFormattedObject() { if (_formatter == null) @@ -46,7 +47,7 @@ private object ReadBinaryFormattedObject() return _formatter.Deserialize(_store.BaseStream); } - +#pragma warning restore SYSLIB0011 internal sealed class UndoTruncatedTypeNameSerializationBinder : SerializationBinder { From b6ca563f1fdf800c3a823c5d7dc2ac1e136bdea2 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Wed, 23 Jun 2021 10:10:12 +0200 Subject: [PATCH 13/25] Add NetCoreAppCurrent to S.N.H.WinHttpHandler --- .../System.Net.Http.WinHttpHandler.pkgproj | 1 + .../ref/System.Net.Http.WinHttpHandler.csproj | 11 +++++- .../src/System.Net.Http.WinHttpHandler.csproj | 37 +++++++++++++++---- .../System/Net/Http/WinHttpResponseStream.cs | 2 +- .../System/Net/Http/WinHttpTrailersHelper.cs | 4 +- 5 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/libraries/System.Net.Http.WinHttpHandler/pkg/System.Net.Http.WinHttpHandler.pkgproj b/src/libraries/System.Net.Http.WinHttpHandler/pkg/System.Net.Http.WinHttpHandler.pkgproj index e7c9f89774588..ef0dd9c8911c2 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/pkg/System.Net.Http.WinHttpHandler.pkgproj +++ b/src/libraries/System.Net.Http.WinHttpHandler/pkg/System.Net.Http.WinHttpHandler.pkgproj @@ -6,6 +6,7 @@ + \ No newline at end of file diff --git a/src/libraries/System.Net.Http.WinHttpHandler/ref/System.Net.Http.WinHttpHandler.csproj b/src/libraries/System.Net.Http.WinHttpHandler/ref/System.Net.Http.WinHttpHandler.csproj index 806d5504734c7..abb8c9bcb21f6 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/ref/System.Net.Http.WinHttpHandler.csproj +++ b/src/libraries/System.Net.Http.WinHttpHandler/ref/System.Net.Http.WinHttpHandler.csproj @@ -1,12 +1,19 @@ - netstandard2.0;net461 + $(NetCoreAppCurrent);netstandard2.0;net461 enable + - + + + + + + + \ No newline at end of file diff --git a/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj b/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj index e5a57c97107fd..525d50608ff7d 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj +++ b/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj @@ -1,17 +1,19 @@ true - netstandard2.0-windows;netstandard2.0;netstandard2.1-windows;netstandard2.1;net461-windows + $(NetCoreAppCurrent)-windows;$(NetcoreAppCurrent);netstandard2.1-windows;netstandard2.1;netstandard2.0-windows;netstandard2.0;net461-windows true enable + - SR.PlatformNotSupported_WinHttpHandler + SR.PlatformNotSupported_WinHttpHandler + + annotations - - - + @@ -99,13 +101,34 @@ Link="Common\System\IO\StreamHelpers.CopyValidation.cs" /> + - + + + + + + + + + + + + + + + + + + + - + + diff --git a/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpResponseStream.cs b/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpResponseStream.cs index 16d0235d55331..d7432541b94b9 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpResponseStream.cs +++ b/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpResponseStream.cs @@ -154,7 +154,7 @@ private async Task CopyToAsyncCore(Stream destination, byte[] buffer, Cancellati Debug.Assert(bytesRead > 0); // Write that data out to the output stream -#if NETSTANDARD2_1 +#if NETSTANDARD2_1 || NETCOREAPP await destination.WriteAsync(buffer.AsMemory(0, bytesRead), cancellationToken).ConfigureAwait(false); #else await destination.WriteAsync(buffer, 0, bytesRead, cancellationToken).ConfigureAwait(false); diff --git a/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpTrailersHelper.cs b/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpTrailersHelper.cs index 1254ae8220bc7..9f88437e0c400 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpTrailersHelper.cs +++ b/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpTrailersHelper.cs @@ -11,7 +11,7 @@ namespace System.Net.Http internal static class WinHttpTrailersHelper { // UNITTEST is true when building against WinHttpHandler.Unit.Tests, which includes the source file. -#if !NETSTANDARD2_1 && !UNITTEST +#if !NETSTANDARD2_1 && !NETCOREAPP && !UNITTEST // Trailer property name was chosen to be descriptive and be unlikely to collide with a user set property. // Apps and libraries will use this key so it shouldn't change. private const string RequestMessagePropertyName = "__ResponseTrailers"; @@ -24,7 +24,7 @@ private sealed class HttpResponseTrailers : HttpHeaders public static HttpHeaders GetResponseTrailers(HttpResponseMessage response) { -#if NETSTANDARD2_1 || UNITTEST +#if NETSTANDARD2_1 || NETCOREAPP || UNITTEST return response.TrailingHeaders; #else HttpResponseTrailers responseTrailers = new HttpResponseTrailers(); From efbaa66f5968852dec9fbade6d25f36d0cdc81de Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Thu, 24 Jun 2021 13:36:25 +0200 Subject: [PATCH 14/25] Mark CodeBase with RequireAssemblyFiles --- .../Reflection/Context/Delegation/DelegatingAssembly.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Reflection.Context/src/System/Reflection/Context/Delegation/DelegatingAssembly.cs b/src/libraries/System.Reflection.Context/src/System/Reflection/Context/Delegation/DelegatingAssembly.cs index 8fa2a434924d9..cbbeda045ab17 100644 --- a/src/libraries/System.Reflection.Context/src/System/Reflection/Context/Delegation/DelegatingAssembly.cs +++ b/src/libraries/System.Reflection.Context/src/System/Reflection/Context/Delegation/DelegatingAssembly.cs @@ -72,13 +72,12 @@ public override SecurityRuleSet SecurityRuleSet #if NETCOREAPP [Obsolete] + [RequiresAssemblyFiles] #endif -#pragma warning disable IL3002 // Using member which has 'RequiresAssemblyFilesAttribute' can break functionality when embedded in a single-file app public override string CodeBase { get { return UnderlyingAssembly.CodeBase; } } -#pragma warning restore IL3002 public override object CreateInstance(string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes) { @@ -92,13 +91,12 @@ public override MethodInfo EntryPoint #if NETCOREAPP [Obsolete] + [RequiresAssemblyFiles] #endif -#pragma warning disable IL3002 // Using member which has 'RequiresAssemblyFilesAttribute' can break functionality when embedded in a single-file app public override string EscapedCodeBase { get { return UnderlyingAssembly.EscapedCodeBase; } } -#pragma warning restore IL3002 public override string FullName { From c01683efeedaf5a49528f762dd8cc5d691755da6 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Thu, 24 Jun 2021 13:39:11 +0200 Subject: [PATCH 15/25] Apply serialPort feedback --- .../src/System/IO/Ports/SerialPort.Unix.cs | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.Unix.cs b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.Unix.cs index e41fe33d72b82..65acbb9cc06f6 100644 --- a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.Unix.cs +++ b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.Unix.cs @@ -13,22 +13,16 @@ public partial class SerialPort : Component { public static string[] GetPortNames() { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - return GetPortNames_Linux(); - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - { - return GetPortNames_OSX(); - } #if NETCOREAPP - else if (RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD)) - { - return GetPortNames_FreeBSD(); - } + return OperatingSystem.IsLinux() ? GetPortNames_Linux() + : OperatingSystem.IsMacOS() ? GetPortNames_OSX() + : OperatingSystem.IsFreeBSD() ? GetPortNames_FreeBSD() +#else + return RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? GetPortNames_Linux() + : RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? GetPortNames_OSX() + : RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")) ? GetPortNames_FreeBSD() #endif - - throw new PlatformNotSupportedException(SR.PlatformNotSupported_SerialPort_GetPortNames); + : throw new PlatformNotSupportedException(SR.PlatformNotSupported_SerialPort_GetPortNames); } private static string[] GetPortNames_Linux() @@ -117,7 +111,6 @@ private static string[] GetPortNames_OSX() return ports.ToArray(); } -#if NETCOREAPP private static string[] GetPortNames_FreeBSD() { List ports = new List(); @@ -140,6 +133,5 @@ private static string[] GetPortNames_FreeBSD() return ports.ToArray(); } -#endif } } From 88b65369a60edb7a2fc6f91bc6545945fb22c66f Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Thu, 24 Jun 2021 13:46:30 +0200 Subject: [PATCH 16/25] Apply SerialStream feedback --- .../src/System/IO/Ports/SerialStream.Unix.cs | 50 ++++++++----------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs index 67ab481321550..f9eb39f3af28a 100644 --- a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs +++ b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs @@ -423,14 +423,8 @@ internal int Read(byte[] array, int offset, int count, int timeout) public override int EndRead(IAsyncResult asyncResult) => EndReadWrite(asyncResult); - public override Task ReadAsync(byte[] array, int offset, int count, CancellationToken cancellationToken) + private Task ReadInternalAsync(Memory buffer, CancellationToken cancellationToken) { - CheckReadWriteArguments(array, offset, count); - - if (count == 0) - return Task.FromResult(0); // return immediately if no bytes requested; no need for overhead. - - Memory buffer = new Memory(array, offset, count); SerialStreamIORequest result = new(cancellationToken, buffer); _readQueue.Enqueue(result); @@ -439,44 +433,40 @@ public override Task ReadAsync(byte[] array, int offset, int count, Cancell return result.Task; } -#if NETCOREAPP - public override ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default) + private Task WriteInternalAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken) { SerialStreamIORequest result = new(cancellationToken, buffer); - _readQueue.Enqueue(result); + _writeQueue.Enqueue(result); EnsureIOLoopRunning(); - return new ValueTask(result.Task); + return result.Task; } -#endif - public override Task WriteAsync(byte[] array, int offset, int count, CancellationToken cancellationToken) + public override Task ReadAsync(byte[] array, int offset, int count, CancellationToken cancellationToken) { - CheckWriteArguments(array, offset, count); - - if (count == 0) - return Task.CompletedTask; // return immediately if no bytes to write; no need for overhead. + CheckReadWriteArguments(array, offset, count); - Memory buffer = new Memory(array, offset, count); - SerialStreamIORequest result = new(cancellationToken, buffer); - _writeQueue.Enqueue(result); + return count == 0 + ? Task.FromResult(0) // return immediately if no bytes requested; no need for overhead. + : ReadInternalAsync(new Memory(array, offset, count), cancellationToken); + } - EnsureIOLoopRunning(); + public override Task WriteAsync(byte[] array, int offset, int count, CancellationToken cancellationToken) + { + CheckWriteArguments(array, offset, count); - return result.Task; + return count == 0 + ? Task.CompletedTask // return immediately if no bytes to write; no need for overhead. + : WriteInternalAsync(new ReadOnlyMemory(array, offset, count), cancellationToken); } #if NETCOREAPP - public override ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default) - { - SerialStreamIORequest result = new(cancellationToken, buffer); - _writeQueue.Enqueue(result); - - EnsureIOLoopRunning(); + public override ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default) + => new ValueTask(ReadInternalAsync(buffer, cancellationToken)); - return new ValueTask(result.Task); - } + public override ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default) + => new ValueTask(WriteInternalAsync(buffer, cancellationToken)); #endif public override IAsyncResult BeginRead(byte[] array, int offset, int numBytes, AsyncCallback userCallback, object stateObject) From 9e11a158f18c0b03de712206be46451f3dce65ba Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Thu, 24 Jun 2021 16:57:04 +0200 Subject: [PATCH 17/25] Avoid ifdefs --- .../src/DbConnectionOptions.cs | 27 ++----------------- .../src/System.Data.OleDb.csproj | 2 ++ .../src/System/Data/Common/AdapterUtil.cs | 4 --- .../src/System.IO.Packaging.csproj | 2 ++ .../src/System/IO/Packaging/PackUriHelper.cs | 6 +---- .../src/System.Resources.Extensions.csproj | 2 ++ .../Extensions/DeserializingResourceReader.cs | 4 +-- 7 files changed, 10 insertions(+), 37 deletions(-) diff --git a/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs b/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs index 53e31f09c3b34..474c378a71d6c 100644 --- a/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs +++ b/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs @@ -228,11 +228,7 @@ internal static void AppendKeyValuePairBuilder(StringBuilder builder, string key // -> builder.Append(keyValue); } -#if NETCOREAPP - else if (keyValue.Contains('\"') && !keyValue.Contains('\'')) -#else else if ((-1 != keyValue.IndexOf('\"')) && (-1 == keyValue.IndexOf('\''))) -#endif { // -> <'val"ue'> builder.Append('\''); @@ -770,17 +766,9 @@ private static bool IsValueValidInternal(string? keyvalue) { #if DEBUG bool compValue = ConnectionStringValidValueRegex.IsMatch(keyvalue); -#if NETCOREAPP - Debug.Assert(!keyvalue.Contains('\u0000') == compValue, "IsValueValid mismatch with regex"); -#else Debug.Assert((-1 == keyvalue.IndexOf('\u0000')) == compValue, "IsValueValid mismatch with regex"); #endif -#endif -#if NETCOREAPP - return !keyvalue.Contains('\u0000'); -#else return (-1 == keyvalue.IndexOf('\u0000')); -#endif } return true; } @@ -791,20 +779,9 @@ private static bool IsKeyNameValid([NotNullWhen(true)] string? keyname) { #if DEBUG bool compValue = ConnectionStringValidKeyRegex.IsMatch(keyname); - Debug.Assert(((0 < keyname.Length) && (';' != keyname[0]) && !char.IsWhiteSpace(keyname[0]) && -#if NETCOREAPP - !keyname.Contains('\u0000') -#else - (-1 == keyname.IndexOf('\u0000')) -#endif - ) == compValue, "IsValueValid mismatch with regex"); -#endif - return ((0 < keyname.Length) && (';' != keyname[0]) && !char.IsWhiteSpace(keyname[0]) && -#if NETCOREAPP - !keyname.Contains('\u0000')); -#else - (-1 == keyname.IndexOf('\u0000'))); + Debug.Assert(((0 < keyname.Length) && (';' != keyname[0]) && !char.IsWhiteSpace(keyname[0]) && (-1 == keyname.IndexOf('\u0000'))) == compValue, "IsValueValid mismatch with regex"); #endif + return ((0 < keyname.Length) && (';' != keyname[0]) && !char.IsWhiteSpace(keyname[0]) && (-1 == keyname.IndexOf('\u0000'))); } return false; } diff --git a/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj b/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj index 992d0e6b42b9f..f6a245bd40931 100644 --- a/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj +++ b/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj @@ -4,6 +4,8 @@ $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent);netstandard2.0-windows;netstandard2.0;net461-windows true enable + + $(NoWarn);CA2249 diff --git a/src/libraries/System.Data.OleDb/src/System/Data/Common/AdapterUtil.cs b/src/libraries/System.Data.OleDb/src/System/Data/Common/AdapterUtil.cs index 491033233776d..f5bacfd623917 100644 --- a/src/libraries/System.Data.OleDb/src/System/Data/Common/AdapterUtil.cs +++ b/src/libraries/System.Data.OleDb/src/System/Data/Common/AdapterUtil.cs @@ -1016,11 +1016,7 @@ internal static void EscapeSpecialCharacters(string unescapedString, StringBuild foreach (char currentChar in unescapedString) { -#if NETCOREAPP - if (specialCharacters.Contains(currentChar)) -#else if (specialCharacters.IndexOf(currentChar) >= 0) -#endif { escapedString.Append('\\'); } diff --git a/src/libraries/System.IO.Packaging/src/System.IO.Packaging.csproj b/src/libraries/System.IO.Packaging/src/System.IO.Packaging.csproj index a0603ef6e1370..ad04fa37aeaa5 100644 --- a/src/libraries/System.IO.Packaging/src/System.IO.Packaging.csproj +++ b/src/libraries/System.IO.Packaging/src/System.IO.Packaging.csproj @@ -3,6 +3,8 @@ true $(NetCoreAppCurrent);netstandard2.0;net461 enable + + $(NoWarn);CS1847 diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.cs index 179e71e3438bb..46f02c47e8e93 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.cs @@ -466,11 +466,7 @@ private static void ThrowIfFragmentPresent(string partName) private static ArgumentException? GetExceptionIfFragmentPresent(string partName) { -#if NETCOREAPP - if (partName.Contains('#')) // string.Contains(char) is .NetCore2.1+ specific -#else - if (partName.Contains("#")) -#endif + if (partName.Contains("#")) // string.Contains(char) is .NetCore2.1+ specific return new ArgumentException(SR.PartUriCannotHaveAFragment); else return null; diff --git a/src/libraries/System.Resources.Extensions/src/System.Resources.Extensions.csproj b/src/libraries/System.Resources.Extensions/src/System.Resources.Extensions.csproj index adacc9b977e5b..a048d43fb373f 100644 --- a/src/libraries/System.Resources.Extensions/src/System.Resources.Extensions.csproj +++ b/src/libraries/System.Resources.Extensions/src/System.Resources.Extensions.csproj @@ -3,6 +3,8 @@ true $(NetCoreAppCurrent);netstandard2.0;net461 $(DefineConstants);RESOURCES_EXTENSIONS + + $(NoWarn);SYSLIB0011 enable diff --git a/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/DeserializingResourceReader.cs b/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/DeserializingResourceReader.cs index ef40926e32aac..bfd29fa995a96 100644 --- a/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/DeserializingResourceReader.cs +++ b/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/DeserializingResourceReader.cs @@ -33,8 +33,7 @@ private bool ValidateReaderType(string readerType) return false; } -// Issue https://github.com/dotnet/runtime/issues/39292 tracks finding an alternative to BinaryFormatter -#pragma warning disable SYSLIB0011 + // Issue https://github.com/dotnet/runtime/issues/39292 tracks finding an alternative to BinaryFormatter private object ReadBinaryFormattedObject() { if (_formatter == null) @@ -47,7 +46,6 @@ private object ReadBinaryFormattedObject() return _formatter.Deserialize(_store.BaseStream); } -#pragma warning restore SYSLIB0011 internal sealed class UndoTruncatedTypeNameSerializationBinder : SerializationBinder { From 19ba3814e5ad8915ca2e200ef46c48bb80128629 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Thu, 24 Jun 2021 17:30:33 +0200 Subject: [PATCH 18/25] Fix trailing whitespace lol --- .../System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs index f9eb39f3af28a..eb4aaaec96ca1 100644 --- a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs +++ b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs @@ -447,7 +447,7 @@ public override Task ReadAsync(byte[] array, int offset, int count, Cancell { CheckReadWriteArguments(array, offset, count); - return count == 0 + return count == 0 ? Task.FromResult(0) // return immediately if no bytes requested; no need for overhead. : ReadInternalAsync(new Memory(array, offset, count), cancellationToken); } From ac39e761d6e06046dfb605cc5844d89d98952343 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Thu, 24 Jun 2021 17:54:24 +0200 Subject: [PATCH 19/25] Fix NoWarn --- .../System.IO.Packaging/src/System.IO.Packaging.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.IO.Packaging/src/System.IO.Packaging.csproj b/src/libraries/System.IO.Packaging/src/System.IO.Packaging.csproj index ad04fa37aeaa5..abb185806210a 100644 --- a/src/libraries/System.IO.Packaging/src/System.IO.Packaging.csproj +++ b/src/libraries/System.IO.Packaging/src/System.IO.Packaging.csproj @@ -4,7 +4,7 @@ $(NetCoreAppCurrent);netstandard2.0;net461 enable - $(NoWarn);CS1847 + $(NoWarn);CA1847 From 2a313946724f67dcefa830fcdd366933b5fd6a0d Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Fri, 25 Jun 2021 18:25:15 +0200 Subject: [PATCH 20/25] Remove further ifdefs --- .../System.Data.OleDb/src/ColumnBinding.cs | 10 ----- .../src/DbConnectionOptions.cs | 12 ------ .../System.Data.OleDb/src/DbPropSet.cs | 8 ---- .../System.Data.OleDb/src/OleDbCommand.cs | 6 --- .../System.Data.OleDb/src/OleDbDataReader.cs | 6 --- .../System.Data.OleDb/src/OleDbTransaction.cs | 10 ----- .../System.Data.OleDb/src/OleDbWrapper.cs | 10 ----- .../System.Data.OleDb/src/PropertyInfoSet.cs | 4 -- .../System.Data.OleDb/src/RowBinding.cs | 28 ------------- .../System.Data.OleDb/src/SafeHandles.cs | 8 ---- .../src/System.Data.OleDb.csproj | 2 + .../src/System/Data/ProviderBase/DbBuffer.cs | 42 ------------------- .../Data/ProviderBase/DbConnectionPool.cs | 20 --------- .../Data/ProviderBase/WrappedIUnknown.cs | 4 -- 14 files changed, 2 insertions(+), 168 deletions(-) diff --git a/src/libraries/System.Data.OleDb/src/ColumnBinding.cs b/src/libraries/System.Data.OleDb/src/ColumnBinding.cs index 9f7c87a728048..8eca4d6280676 100644 --- a/src/libraries/System.Data.OleDb/src/ColumnBinding.cs +++ b/src/libraries/System.Data.OleDb/src/ColumnBinding.cs @@ -631,9 +631,7 @@ private string Value_BSTR() string value = ""; RowBinding bindings = RowBinding; bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { bindings.DangerousAddRef(ref mustRelease); @@ -668,9 +666,7 @@ private byte[] Value_ByRefBYTES() byte[]? value = null; RowBinding bindings = RowBinding; bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { bindings.DangerousAddRef(ref mustRelease); @@ -718,9 +714,7 @@ private string Value_ByRefWSTR() string value = ""; RowBinding bindings = RowBinding; bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { bindings.DangerousAddRef(ref mustRelease); @@ -1021,9 +1015,7 @@ private object Value_IDISPATCH() object value; RowBinding bindings = RowBinding; bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { bindings.DangerousAddRef(ref mustRelease); @@ -1070,9 +1062,7 @@ private object Value_IUNKNOWN() object value; RowBinding bindings = RowBinding; bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { bindings.DangerousAddRef(ref mustRelease); diff --git a/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs b/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs index 474c378a71d6c..2d47d32c4d9f2 100644 --- a/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs +++ b/src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs @@ -367,29 +367,17 @@ protected internal virtual string Expand() if (!rootFolderEndsWith && !fileNameStartsWith) { // need to insert '\' -#if NETCOREAPP - fullPath = string.Concat(rootFolderPath + '\\', value.AsSpan(fileNamePosition)); -#else fullPath = rootFolderPath + '\\' + value.Substring(fileNamePosition); -#endif } else if (rootFolderEndsWith && fileNameStartsWith) { // need to strip one out -#if NETCOREAPP - fullPath = string.Concat(rootFolderPath, value.AsSpan(fileNamePosition + 1)); -#else fullPath = rootFolderPath + value.Substring(fileNamePosition + 1); -#endif } else { // simply concatenate the strings -#if NETCOREAPP - fullPath = string.Concat(rootFolderPath, value.AsSpan(fileNamePosition)); -#else fullPath = rootFolderPath + value.Substring(fileNamePosition); -#endif } // verify root folder path is a real path without unexpected "..\" diff --git a/src/libraries/System.Data.OleDb/src/DbPropSet.cs b/src/libraries/System.Data.OleDb/src/DbPropSet.cs index 10681aeca4440..19e6263f34602 100644 --- a/src/libraries/System.Data.OleDb/src/DbPropSet.cs +++ b/src/libraries/System.Data.OleDb/src/DbPropSet.cs @@ -25,12 +25,10 @@ internal DBPropSet(int propertysetCount) : this() { this.propertySetCount = propertysetCount; IntPtr countOfBytes = (IntPtr)(propertysetCount * ODB.SizeOf_tagDBPROPSET); -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally -#endif { base.handle = SafeNativeMethods.CoTaskMemAlloc(countOfBytes); if (ADP.PtrZero != base.handle) @@ -177,9 +175,7 @@ internal ItagDBPROP[] GetPropertySet(int index, out Guid propertyset) ItagDBPROP[]? properties = null; bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -227,20 +223,16 @@ internal void SetPropertySet(int index, Guid propertySet, ItagDBPROP[] propertie tagDBPROPSET propset = new tagDBPROPSET(properties.Length, propertySet); bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); IntPtr propsetPtr = ADP.IntPtrOffset(DangerousGetHandle(), index * ODB.SizeOf_tagDBPROPSET); -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally -#endif { // must allocate and clear the memory without interruption propset.rgProperties = SafeNativeMethods.CoTaskMemAlloc(countOfBytes); diff --git a/src/libraries/System.Data.OleDb/src/OleDbCommand.cs b/src/libraries/System.Data.OleDb/src/OleDbCommand.cs index 39b2c638d143e..8c50247f31525 100644 --- a/src/libraries/System.Data.OleDb/src/OleDbCommand.cs +++ b/src/libraries/System.Data.OleDb/src/OleDbCommand.cs @@ -814,9 +814,7 @@ private int ExecuteCommandText(out object executeResult) RowBinding? rowbinding = null; Bindings? bindings = ParameterBindings; bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { if (null != bindings) @@ -972,9 +970,7 @@ private int ExecuteTableDirect(CommandBehavior behavior, out object? executeResu StringMemHandle? sptr = null; bool mustReleaseStringHandle = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { sptr = new StringMemHandle(ExpandCommandText()); @@ -995,9 +991,7 @@ private int ExecuteTableDirect(CommandBehavior behavior, out object? executeResu if (null != propSet) { bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { propSet.DangerousAddRef(ref mustRelease); diff --git a/src/libraries/System.Data.OleDb/src/OleDbDataReader.cs b/src/libraries/System.Data.OleDb/src/OleDbDataReader.cs index da1d2cb6988d6..e50ba5a23b1d0 100644 --- a/src/libraries/System.Data.OleDb/src/OleDbDataReader.cs +++ b/src/libraries/System.Data.OleDb/src/OleDbDataReader.cs @@ -1730,9 +1730,7 @@ private void GetRowHandles(/*int skipCount*/) RowHandleBuffer rowHandleBuffer = _rowHandleNativeBuffer!; bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { rowHandleBuffer.DangerousAddRef(ref mustRelease); @@ -1787,9 +1785,7 @@ private void GetRowDataFromHandle() IntPtr accessorHandle = rowBinding.DangerousGetAccessorHandle(); bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { rowBinding.DangerousAddRef(ref mustRelease); @@ -1884,9 +1880,7 @@ private void GetRowValue() bool mustReleaseBinding = false; bool[] mustRelease = new bool[columnBindings.Length]; StringMemHandle?[] sptr = new StringMemHandle[columnBindings.Length]; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { for (int i = 0; i < columnBindings.Length; ++i) diff --git a/src/libraries/System.Data.OleDb/src/OleDbTransaction.cs b/src/libraries/System.Data.OleDb/src/OleDbTransaction.cs index 6df9c7728a164..2181a6cbe75af 100644 --- a/src/libraries/System.Data.OleDb/src/OleDbTransaction.cs +++ b/src/libraries/System.Data.OleDb/src/OleDbTransaction.cs @@ -26,12 +26,10 @@ private sealed class WrappedTransaction : WrappedIUnknown internal WrappedTransaction(UnsafeNativeMethods.ITransactionLocal transaction, int isolevel, out OleDbHResult hr) : base(transaction) { int transactionLevel = 0; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally -#endif { hr = transaction.StartTransaction(isolevel, 0, IntPtr.Zero, out transactionLevel); if (0 <= hr) @@ -51,18 +49,14 @@ internal OleDbHResult Abort() Debug.Assert(_mustComplete, "transaction already completed"); OleDbHResult hr; bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally -#endif { hr = (OleDbHResult)NativeOledbWrapper.ITransactionAbort(DangerousGetHandle()); _mustComplete = false; @@ -83,18 +77,14 @@ internal OleDbHResult Commit() Debug.Assert(_mustComplete, "transaction already completed"); OleDbHResult hr; bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally -#endif { hr = (OleDbHResult)NativeOledbWrapper.ITransactionCommit(DangerousGetHandle()); if ((0 <= (int)hr) || (OleDbHResult.XACT_E_NOTRANSACTION == hr)) diff --git a/src/libraries/System.Data.OleDb/src/OleDbWrapper.cs b/src/libraries/System.Data.OleDb/src/OleDbWrapper.cs index 77de0cadcd8b8..23ef6c6b0d495 100644 --- a/src/libraries/System.Data.OleDb/src/OleDbWrapper.cs +++ b/src/libraries/System.Data.OleDb/src/OleDbWrapper.cs @@ -24,12 +24,10 @@ internal OleDbServicesWrapper(object? unknown) : base() { if (null != unknown) { -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally -#endif { // store the QI result for IID_IDataInitialize base.handle = Marshal.GetComInterfaceForObject(unknown, typeof(UnsafeNativeMethods.IDataInitialize)); @@ -48,9 +46,7 @@ internal void GetDataSource(OleDbConnectionString constr, ref DataSourceWrapper OleDbHResult hr; UnsafeNativeMethods.IDataInitializeGetDataSource GetDataSource = DangerousIDataInitializeGetDataSource!; bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -105,9 +101,7 @@ internal OleDbHResult InitializeAndCreateSession(OleDbConnectionString constr, r OleDbHResult hr; bool mustRelease = false; IntPtr idbCreateSession = IntPtr.Zero; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -260,9 +254,7 @@ internal void QueryInterfaceIDBCreateCommand(OleDbConnectionString constr) if (!constr.HaveQueriedForCreateCommand || (null != constr.DangerousIDBCreateCommandCreateCommand)) { IntPtr idbCreateCommand = IntPtr.Zero; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { // native COM rules are the QI result is the 'this' pointer @@ -335,9 +327,7 @@ internal OleDbHResult CreateCommand(ref object? icommandText) if (null != CreateCommand) { bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); diff --git a/src/libraries/System.Data.OleDb/src/PropertyInfoSet.cs b/src/libraries/System.Data.OleDb/src/PropertyInfoSet.cs index 9c36259df011f..60b44bab7de48 100644 --- a/src/libraries/System.Data.OleDb/src/PropertyInfoSet.cs +++ b/src/libraries/System.Data.OleDb/src/PropertyInfoSet.cs @@ -33,12 +33,10 @@ internal PropertyInfoSet(UnsafeNativeMethods.IDBProperties idbProperties, Proper { OleDbHResult hr; int propIDSetCount = propIDSet.Count; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally -#endif { hr = idbProperties.GetPropertyInfo(propIDSetCount, propIDSet, out this.setCount, out base.handle, out this.descBuffer); } @@ -61,9 +59,7 @@ public override bool IsInvalid Dictionary? propertyLookup = null; bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); diff --git a/src/libraries/System.Data.OleDb/src/RowBinding.cs b/src/libraries/System.Data.OleDb/src/RowBinding.cs index 39df330f8b485..2d313ea42b453 100644 --- a/src/libraries/System.Data.OleDb/src/RowBinding.cs +++ b/src/libraries/System.Data.OleDb/src/RowBinding.cs @@ -125,9 +125,7 @@ internal ColumnBinding[] SetBindings(OleDbDataReader? dataReader, Bindings bindi Debug.Assert(dbbindings.Length == BindingCount(), "count mismatch"); bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -175,9 +173,7 @@ internal object GetVariantValue(int offset) object? value = null; bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -207,17 +203,13 @@ internal void SetVariantValue(int offset, object value) IntPtr buffer = ADP.PtrZero; bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); buffer = ADP.IntPtrOffset(DangerousGetHandle(), offset); -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { // GetNativeVariantForObject must be in try block since it has no reliability contract @@ -251,18 +243,14 @@ internal void SetBstrValue(int offset, string value) IntPtr ptr; bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally -#endif { ptr = SafeNativeMethods.SysAllocStringLen(value, value.Length); @@ -296,18 +284,14 @@ internal void SetByRefValue(int offset, IntPtr pinnedValue) pinnedValue = ADP.IntPtrOffset(base.handle, _emptyStringOffset); } bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally -#endif { Marshal.WriteIntPtr(base.handle, offset, pinnedValue); // parameter input value Marshal.WriteIntPtr(base.handle, offset + ADP.PtrSize, pinnedValue); // original parameter value @@ -360,9 +344,7 @@ internal void ResetValues() { // prevent Dispose/ResetValues race condition bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -501,12 +483,10 @@ private static void FreeBstr(IntPtr buffer, int valueOffset) // two contigous BSTR ptrs that need to be freed // the second should only be freed if different from the first -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally -#endif { IntPtr currentValue = Marshal.ReadIntPtr(buffer, valueOffset); IntPtr originalValue = Marshal.ReadIntPtr(buffer, valueOffset + ADP.PtrSize); @@ -532,12 +512,10 @@ private static void FreeCoTaskMem(IntPtr buffer, int valueOffset) // two contigous CoTaskMemAlloc ptrs that need to be freed // the first should only be freed if different from the first -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally -#endif { IntPtr currentValue = Marshal.ReadIntPtr(buffer, valueOffset); IntPtr originalValue = Marshal.ReadIntPtr(buffer, valueOffset + ADP.PtrSize); @@ -565,12 +543,10 @@ private static void FreeVariant(IntPtr buffer, int valueOffset) IntPtr currentHandle = ADP.IntPtrOffset(buffer, valueOffset); IntPtr originalHandle = ADP.IntPtrOffset(buffer, valueOffset + ODB.SizeOf_Variant); bool different = NativeOledbWrapper.MemoryCompare(currentHandle, originalHandle, ODB.SizeOf_Variant); -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally -#endif { // always clear the first structure SafeNativeMethods.VariantClear(currentHandle); @@ -597,12 +573,10 @@ private static unsafe void FreePropVariant(IntPtr buffer, int valueOffset) IntPtr currentHandle = ADP.IntPtrOffset(buffer, valueOffset); IntPtr originalHandle = ADP.IntPtrOffset(buffer, valueOffset + sizeof(PROPVARIANT)); bool different = NativeOledbWrapper.MemoryCompare(currentHandle, originalHandle, sizeof(PROPVARIANT)); -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally -#endif { // always clear the first structure SafeNativeMethods.PropVariantClear(currentHandle); @@ -626,9 +600,7 @@ internal IntPtr InterlockedExchangePointer(int offset) IntPtr value; bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); diff --git a/src/libraries/System.Data.OleDb/src/SafeHandles.cs b/src/libraries/System.Data.OleDb/src/SafeHandles.cs index e73a42f07c6a9..d435f7f45bcd1 100644 --- a/src/libraries/System.Data.OleDb/src/SafeHandles.cs +++ b/src/libraries/System.Data.OleDb/src/SafeHandles.cs @@ -135,12 +135,10 @@ private ChapterHandle(IntPtr chapter) : base((object?)null) private ChapterHandle(object chapteredRowset, RowBinding binding, int valueOffset) : base(chapteredRowset) { -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally -#endif { _chapterHandle = binding.InterlockedExchangePointer(valueOffset); } @@ -668,12 +666,10 @@ internal static unsafe OleDbHResult IChapteredRowsetReleaseChapter(System.IntPtr OleDbHResult hr = OleDbHResult.E_UNEXPECTED; IntPtr hchapter = chapter; System.Data.Common.UnsafeNativeMethods.IChapteredRowset? chapteredRowset = null; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally -#endif { Guid IID_IChapteredRowset = typeof(System.Data.Common.UnsafeNativeMethods.IChapteredRowset).GUID; hr = (OleDbHResult)Marshal.QueryInterface(ptr, ref IID_IChapteredRowset, out var pChapteredRowset); @@ -692,12 +688,10 @@ internal static unsafe OleDbHResult ITransactionAbort(System.IntPtr ptr) { OleDbHResult hr = OleDbHResult.E_UNEXPECTED; ITransactionLocal? transactionLocal = null; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally -#endif { Guid IID_ITransactionLocal = typeof(ITransactionLocal).GUID; hr = (OleDbHResult)Marshal.QueryInterface(ptr, ref IID_ITransactionLocal, out var pTransaction); @@ -716,12 +710,10 @@ internal static unsafe OleDbHResult ITransactionCommit(System.IntPtr ptr) { OleDbHResult hr = OleDbHResult.E_UNEXPECTED; ITransactionLocal? transactionLocal = null; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally -#endif { Guid IID_ITransactionLocal = typeof(ITransactionLocal).GUID; hr = (OleDbHResult)Marshal.QueryInterface(ptr, ref IID_ITransactionLocal, out var pTransaction); diff --git a/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj b/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj index f6a245bd40931..a7d17e7738eb1 100644 --- a/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj +++ b/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj @@ -6,6 +6,8 @@ enable $(NoWarn);CA2249 + + $(NoWarn);SYSLIB0004 diff --git a/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbBuffer.cs b/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbBuffer.cs index 54031316fd6e1..dc0db72fa5c6c 100644 --- a/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbBuffer.cs +++ b/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbBuffer.cs @@ -25,12 +25,10 @@ private DbBuffer(int initialSize, bool zeroBuffer) : base(IntPtr.Zero, true) int flags = ((zeroBuffer) ? LMEM_ZEROINIT : LMEM_FIXED); _bufferLength = initialSize; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally -#endif { base.handle = SafeNativeMethods.LocalAlloc(flags, (IntPtr)initialSize); } @@ -75,9 +73,7 @@ internal string PtrToStringUni(int offset, int length) string? value = null; bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -103,9 +99,7 @@ internal byte ReadByte(int offset) byte value; bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -138,9 +132,7 @@ internal byte[] ReadBytes(int offset, byte[] destination, int startIndex, int le Debug.Assert(startIndex + length <= destination.Length, "destination too small"); bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -173,9 +165,7 @@ internal char[] ReadChars(int offset, char[] destination, int startIndex, int le Debug.Assert(startIndex + length <= destination.Length, "destination too small"); bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -207,9 +197,7 @@ internal short ReadInt16(int offset) short value; bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -236,9 +224,7 @@ internal void ReadInt16Array(int offset, short[] destination, int startIndex, in Debug.Assert(startIndex + length <= destination.Length, "destination too small"); bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -263,9 +249,7 @@ internal int ReadInt32(int offset) int value; bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -292,9 +276,7 @@ internal void ReadInt32Array(int offset, int[] destination, int startIndex, int Debug.Assert(startIndex + length <= destination.Length, "destination too small"); bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -319,9 +301,7 @@ internal long ReadInt64(int offset) long value; bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -347,9 +327,7 @@ internal IntPtr ReadIntPtr(int offset) IntPtr value; bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -393,9 +371,7 @@ private void StructureToPtr(int offset, object structure) Debug.Assert(0 == offset % ADP.PtrSize, "invalid alignment"); bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -419,9 +395,7 @@ internal void WriteByte(int offset, byte value) Debug.Assert(0 == offset % 4, "invalid alignment"); bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -447,9 +421,7 @@ internal void WriteBytes(int offset, byte[] source, int startIndex, int length) Debug.Assert(startIndex + length <= source.Length, "source too small"); bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -475,9 +447,7 @@ internal void WriteCharArray(int offset, char[] source, int startIndex, int leng Debug.Assert(startIndex + length <= source.Length, "source too small"); bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -506,9 +476,7 @@ internal void WriteInt16(int offset, short value) Debug.Assert(0 == offset % 2, "invalid alignment"); bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -534,9 +502,7 @@ internal void WriteInt16Array(int offset, short[] source, int startIndex, int le Debug.Assert(startIndex + length <= source.Length, "source too small"); bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -560,9 +526,7 @@ internal void WriteInt32(int offset, int value) Debug.Assert(0 == offset % 4, "invalid alignment"); bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -588,9 +552,7 @@ internal void WriteInt32Array(int offset, int[] source, int startIndex, int leng Debug.Assert(startIndex + length <= source.Length, "source too small"); bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -614,9 +576,7 @@ internal void WriteInt64(int offset, long value) Debug.Assert(0 == offset % IntPtr.Size, "invalid alignment"); bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); @@ -640,9 +600,7 @@ internal void WriteIntPtr(int offset, IntPtr value) Debug.Assert(0 == offset % IntPtr.Size, "invalid alignment"); bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); diff --git a/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbConnectionPool.cs b/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbConnectionPool.cs index 4ce824be6fef4..6524001fe7475 100644 --- a/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbConnectionPool.cs +++ b/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbConnectionPool.cs @@ -240,9 +240,7 @@ internal PoolWaitHandles() : base(3 * IntPtr.Size) _poolSemaphore = new Semaphore(0, MAX_Q_SIZE); _errorEvent = new ManualResetEvent(false); _creationSemaphore = new Semaphore(1, 1); -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { // because SafeWaitHandle doesn't have reliability contract @@ -731,12 +729,10 @@ private DbConnectionInternal CreateObject(DbConnection? owningObject, DbConnecti // timer allocation has to be done out of CER block Timer t = new Timer(new TimerCallback(this.ErrorCallback), null, Timeout.Infinite, Timeout.Infinite); bool timerIsNotDisposed; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally -#endif { _waitHandles.ErrorEvent.Set(); _errorOccurred = true; @@ -954,17 +950,13 @@ private void WaitForPendingOpen() do { bool started = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally -#endif { started = Interlocked.CompareExchange(ref _pendingOpensWaiting, 1, 0) == 0; } @@ -994,9 +986,7 @@ private void WaitForPendingOpen() DbConnectionInternal? connection = null; bool timeout = false; Exception? caughtException = null; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { bool allowCreate = true; @@ -1136,18 +1126,14 @@ private bool TryGetConnection(DbConnection owningObject, uint waitForMultipleObj bool mustRelease = false; int waitForMultipleObjectsExHR = 0; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { _waitHandles.DangerousAddRef(ref mustRelease); // We absolutely must have the value of waitResult set, // or we may leak the mutex in async abort cases. -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { Debug.Assert(2 == waitHandleCount || 3 == waitHandleCount, "unexpected waithandle count"); @@ -1242,9 +1228,7 @@ private bool TryGetConnection(DbConnection owningObject, uint waitForMultipleObj { if (_waitHandles.CreationSemaphore.WaitOne(unchecked((int)waitForMultipleObjectsTimeout))) { -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { obj = UserCreateRequest(owningObject, userOptions); @@ -1462,21 +1446,17 @@ private void PoolCreateRequest(object? state) bool mustRelease = false; int waitResult = BOGUS_HANDLE; uint timeout = (uint)CreationTimeout; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { _waitHandles.DangerousAddRef(ref mustRelease); // Obtain creation mutex so we're the only one creating objects // and we must have the wait result -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally -#endif { waitResult = SafeNativeMethods.WaitForSingleObjectEx(_waitHandles.CreationHandle.DangerousGetHandle(), timeout, false); } diff --git a/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/WrappedIUnknown.cs b/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/WrappedIUnknown.cs index 3f7143456aa2f..9b3205849d249 100644 --- a/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/WrappedIUnknown.cs +++ b/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/WrappedIUnknown.cs @@ -22,12 +22,10 @@ internal WrappedIUnknown(object? unknown) : this() { if (null != unknown) { -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); try { } finally -#endif { base.handle = Marshal.GetIUnknownForObject(unknown); } @@ -48,9 +46,7 @@ internal object ComWrapper() // runtime in the debugger. object? value = null; bool mustRelease = false; -#if !NETCOREAPP RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { DangerousAddRef(ref mustRelease); From 93fe1129e1494a75c3dac673dbda37cce590523e Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Fri, 25 Jun 2021 18:50:12 +0200 Subject: [PATCH 21/25] Add pragma warning back --- .../src/System.Resources.Extensions.csproj | 2 -- .../Resources/Extensions/DeserializingResourceReader.cs | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Resources.Extensions/src/System.Resources.Extensions.csproj b/src/libraries/System.Resources.Extensions/src/System.Resources.Extensions.csproj index a048d43fb373f..adacc9b977e5b 100644 --- a/src/libraries/System.Resources.Extensions/src/System.Resources.Extensions.csproj +++ b/src/libraries/System.Resources.Extensions/src/System.Resources.Extensions.csproj @@ -3,8 +3,6 @@ true $(NetCoreAppCurrent);netstandard2.0;net461 $(DefineConstants);RESOURCES_EXTENSIONS - - $(NoWarn);SYSLIB0011 enable diff --git a/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/DeserializingResourceReader.cs b/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/DeserializingResourceReader.cs index bfd29fa995a96..ef40926e32aac 100644 --- a/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/DeserializingResourceReader.cs +++ b/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/DeserializingResourceReader.cs @@ -33,7 +33,8 @@ private bool ValidateReaderType(string readerType) return false; } - // Issue https://github.com/dotnet/runtime/issues/39292 tracks finding an alternative to BinaryFormatter +// Issue https://github.com/dotnet/runtime/issues/39292 tracks finding an alternative to BinaryFormatter +#pragma warning disable SYSLIB0011 private object ReadBinaryFormattedObject() { if (_formatter == null) @@ -46,6 +47,7 @@ private object ReadBinaryFormattedObject() return _formatter.Deserialize(_store.BaseStream); } +#pragma warning restore SYSLIB0011 internal sealed class UndoTruncatedTypeNameSerializationBinder : SerializationBinder { From 46f956275609c8e702d179e36e763201c89096b0 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Fri, 25 Jun 2021 19:04:02 +0200 Subject: [PATCH 22/25] Suppress CA1845 --- src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj | 4 +++- .../System.IO.Ports/src/System/IO/Ports/SerialPort.Unix.cs | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj b/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj index a7d17e7738eb1..27ffeb6ecd338 100644 --- a/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj +++ b/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj @@ -6,8 +6,10 @@ enable $(NoWarn);CA2249 - + $(NoWarn);SYSLIB0004 + + $(NoWarn);CA1845 diff --git a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.Unix.cs b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.Unix.cs index 65acbb9cc06f6..79cc4a791f7ae 100644 --- a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.Unix.cs +++ b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPort.Unix.cs @@ -18,8 +18,8 @@ public static string[] GetPortNames() : OperatingSystem.IsMacOS() ? GetPortNames_OSX() : OperatingSystem.IsFreeBSD() ? GetPortNames_FreeBSD() #else - return RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? GetPortNames_Linux() - : RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? GetPortNames_OSX() + return RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? GetPortNames_Linux() + : RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? GetPortNames_OSX() : RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")) ? GetPortNames_FreeBSD() #endif : throw new PlatformNotSupportedException(SR.PlatformNotSupported_SerialPort_GetPortNames); From 20834c0c9f6378083fc053ac804cae76f553a2cb Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Mon, 28 Jun 2021 21:04:20 +0200 Subject: [PATCH 23/25] Fix unnecessary empty line changes --- src/libraries/System.Data.OleDb/src/DbPropSet.cs | 1 + src/libraries/System.Data.OleDb/src/OleDbCommand.cs | 2 ++ .../System.Data.OleDb/src/OleDbConnectionString.cs | 4 ---- src/libraries/System.Data.OleDb/src/RowBinding.cs | 6 ++++++ .../src/System/Data/ProviderBase/DbConnectionPool.cs | 4 ++++ 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Data.OleDb/src/DbPropSet.cs b/src/libraries/System.Data.OleDb/src/DbPropSet.cs index 19e6263f34602..756c4612c3f1f 100644 --- a/src/libraries/System.Data.OleDb/src/DbPropSet.cs +++ b/src/libraries/System.Data.OleDb/src/DbPropSet.cs @@ -229,6 +229,7 @@ internal void SetPropertySet(int index, Guid propertySet, ItagDBPROP[] propertie DangerousAddRef(ref mustRelease); IntPtr propsetPtr = ADP.IntPtrOffset(DangerousGetHandle(), index * ODB.SizeOf_tagDBPROPSET); + RuntimeHelpers.PrepareConstrainedRegions(); try { } diff --git a/src/libraries/System.Data.OleDb/src/OleDbCommand.cs b/src/libraries/System.Data.OleDb/src/OleDbCommand.cs index 8c50247f31525..a6b9503e0abf6 100644 --- a/src/libraries/System.Data.OleDb/src/OleDbCommand.cs +++ b/src/libraries/System.Data.OleDb/src/OleDbCommand.cs @@ -814,6 +814,7 @@ private int ExecuteCommandText(out object executeResult) RowBinding? rowbinding = null; Bindings? bindings = ParameterBindings; bool mustRelease = false; + RuntimeHelpers.PrepareConstrainedRegions(); try { @@ -970,6 +971,7 @@ private int ExecuteTableDirect(CommandBehavior behavior, out object? executeResu StringMemHandle? sptr = null; bool mustReleaseStringHandle = false; + RuntimeHelpers.PrepareConstrainedRegions(); try { diff --git a/src/libraries/System.Data.OleDb/src/OleDbConnectionString.cs b/src/libraries/System.Data.OleDb/src/OleDbConnectionString.cs index 4ecaa7e29fcdd..e31ff207c5709 100644 --- a/src/libraries/System.Data.OleDb/src/OleDbConnectionString.cs +++ b/src/libraries/System.Data.OleDb/src/OleDbConnectionString.cs @@ -112,11 +112,7 @@ internal OleDbConnectionString(string connectionString, bool validate) : base(co if (!ADP.IsEmpty(udlConnectionString)) { -#if NETCOREAPP - _expandedConnectionString = string.Concat(_expandedConnectionString!.AsSpan(0, position), udlConnectionString + ';', _expandedConnectionString.AsSpan(position)); -#else _expandedConnectionString = _expandedConnectionString!.Substring(0, position) + udlConnectionString + ';' + _expandedConnectionString.Substring(position); -#endif } } } diff --git a/src/libraries/System.Data.OleDb/src/RowBinding.cs b/src/libraries/System.Data.OleDb/src/RowBinding.cs index 2d313ea42b453..7f94bf563d5f1 100644 --- a/src/libraries/System.Data.OleDb/src/RowBinding.cs +++ b/src/libraries/System.Data.OleDb/src/RowBinding.cs @@ -125,6 +125,7 @@ internal ColumnBinding[] SetBindings(OleDbDataReader? dataReader, Bindings bindi Debug.Assert(dbbindings.Length == BindingCount(), "count mismatch"); bool mustRelease = false; + RuntimeHelpers.PrepareConstrainedRegions(); try { @@ -209,6 +210,7 @@ internal void SetVariantValue(int offset, object value) DangerousAddRef(ref mustRelease); buffer = ADP.IntPtrOffset(DangerousGetHandle(), offset); + RuntimeHelpers.PrepareConstrainedRegions(); try { @@ -247,6 +249,7 @@ internal void SetBstrValue(int offset, string value) try { DangerousAddRef(ref mustRelease); + RuntimeHelpers.PrepareConstrainedRegions(); try { } @@ -288,6 +291,7 @@ internal void SetByRefValue(int offset, IntPtr pinnedValue) try { DangerousAddRef(ref mustRelease); + RuntimeHelpers.PrepareConstrainedRegions(); try { } @@ -543,6 +547,7 @@ private static void FreeVariant(IntPtr buffer, int valueOffset) IntPtr currentHandle = ADP.IntPtrOffset(buffer, valueOffset); IntPtr originalHandle = ADP.IntPtrOffset(buffer, valueOffset + ODB.SizeOf_Variant); bool different = NativeOledbWrapper.MemoryCompare(currentHandle, originalHandle, ODB.SizeOf_Variant); + RuntimeHelpers.PrepareConstrainedRegions(); try { } @@ -573,6 +578,7 @@ private static unsafe void FreePropVariant(IntPtr buffer, int valueOffset) IntPtr currentHandle = ADP.IntPtrOffset(buffer, valueOffset); IntPtr originalHandle = ADP.IntPtrOffset(buffer, valueOffset + sizeof(PROPVARIANT)); bool different = NativeOledbWrapper.MemoryCompare(currentHandle, originalHandle, sizeof(PROPVARIANT)); + RuntimeHelpers.PrepareConstrainedRegions(); try { } diff --git a/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbConnectionPool.cs b/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbConnectionPool.cs index 6524001fe7475..e411fc550101f 100644 --- a/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbConnectionPool.cs +++ b/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbConnectionPool.cs @@ -240,6 +240,7 @@ internal PoolWaitHandles() : base(3 * IntPtr.Size) _poolSemaphore = new Semaphore(0, MAX_Q_SIZE); _errorEvent = new ManualResetEvent(false); _creationSemaphore = new Semaphore(1, 1); + RuntimeHelpers.PrepareConstrainedRegions(); try { @@ -950,6 +951,7 @@ private void WaitForPendingOpen() do { bool started = false; + RuntimeHelpers.PrepareConstrainedRegions(); try { @@ -986,6 +988,7 @@ private void WaitForPendingOpen() DbConnectionInternal? connection = null; bool timeout = false; Exception? caughtException = null; + RuntimeHelpers.PrepareConstrainedRegions(); try { @@ -1446,6 +1449,7 @@ private void PoolCreateRequest(object? state) bool mustRelease = false; int waitResult = BOGUS_HANDLE; uint timeout = (uint)CreationTimeout; + RuntimeHelpers.PrepareConstrainedRegions(); try { From 89f85899fd2a6ae7f8d9541fef252afbf70b4021 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Tue, 29 Jun 2021 19:05:39 +0200 Subject: [PATCH 24/25] Revert SerialStream changes --- .../src/System/IO/Ports/SerialStream.Unix.cs | 52 +++++++------------ 1 file changed, 19 insertions(+), 33 deletions(-) diff --git a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs index eb4aaaec96ca1..e9f813fdbe05d 100644 --- a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs +++ b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs @@ -423,51 +423,37 @@ internal int Read(byte[] array, int offset, int count, int timeout) public override int EndRead(IAsyncResult asyncResult) => EndReadWrite(asyncResult); - private Task ReadInternalAsync(Memory buffer, CancellationToken cancellationToken) + public override Task ReadAsync(byte[] array, int offset, int count, CancellationToken cancellationToken) { - SerialStreamIORequest result = new(cancellationToken, buffer); - _readQueue.Enqueue(result); - - EnsureIOLoopRunning(); + CheckReadWriteArguments(array, offset, count); - return result.Task; - } + if (count == 0) + return Task.FromResult(0); // return immediately if no bytes requested; no need for overhead. - private Task WriteInternalAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken) - { - SerialStreamIORequest result = new(cancellationToken, buffer); - _writeQueue.Enqueue(result); + Memory buffer = new Memory(array, offset, count); + SerialStreamIORequest result = new SerialStreamIORequest(cancellationToken, buffer); + _readQueue.Enqueue(result); EnsureIOLoopRunning(); return result.Task; } - public override Task ReadAsync(byte[] array, int offset, int count, CancellationToken cancellationToken) - { - CheckReadWriteArguments(array, offset, count); - - return count == 0 - ? Task.FromResult(0) // return immediately if no bytes requested; no need for overhead. - : ReadInternalAsync(new Memory(array, offset, count), cancellationToken); - } - public override Task WriteAsync(byte[] array, int offset, int count, CancellationToken cancellationToken) { CheckWriteArguments(array, offset, count); - return count == 0 - ? Task.CompletedTask // return immediately if no bytes to write; no need for overhead. - : WriteInternalAsync(new ReadOnlyMemory(array, offset, count), cancellationToken); - } + if (count == 0) + return Task.CompletedTask; // return immediately if no bytes to write; no need for overhead. -#if NETCOREAPP - public override ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default) - => new ValueTask(ReadInternalAsync(buffer, cancellationToken)); + Memory buffer = new Memory(array, offset, count); + SerialStreamIORequest result = new SerialStreamIORequest(cancellationToken, buffer); + _writeQueue.Enqueue(result); - public override ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default) - => new ValueTask(WriteInternalAsync(buffer, cancellationToken)); -#endif + EnsureIOLoopRunning(); + + return result.Task; + } public override IAsyncResult BeginRead(byte[] array, int offset, int numBytes, AsyncCallback userCallback, object stateObject) { @@ -729,7 +715,7 @@ private void RaiseDataReceivedEof() private unsafe int ProcessRead(SerialStreamIORequest r) { - ReadOnlySpan buff = r.Buffer.Span; + Span buff = r.Buffer.Span; fixed (byte* bufPtr = buff) { // assumes dequeue-ing happens on a single thread @@ -978,11 +964,11 @@ private static Exception GetLastIOError() private sealed class SerialStreamIORequest : TaskCompletionSource { - public ReadOnlyMemory Buffer { get; private set; } + public Memory Buffer { get; private set; } public bool IsCompleted => Task.IsCompleted; private CancellationToken _cancellationToken; - public SerialStreamIORequest(CancellationToken ct, ReadOnlyMemory buffer) + public SerialStreamIORequest(CancellationToken ct, Memory buffer) : base(TaskCreationOptions.RunContinuationsAsynchronously) { _cancellationToken = ct; From 5123778f086144bc92e24f6c9f72657e80c30085 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Tue, 29 Jun 2021 19:37:08 +0200 Subject: [PATCH 25/25] Disable SerialStream warning for memory overloads --- .../System.IO.Ports/src/System/IO/Ports/SerialStream.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.cs b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.cs index cec491596eff3..6a8505c7ba1ae 100644 --- a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.cs +++ b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.cs @@ -10,7 +10,12 @@ namespace System.IO.Ports { +// Issue https://github.com/dotnet/runtime/issues/54916 +// 'SerialStream' overrides array-based 'ReadAsync' but does not override memory-based 'ReadAsync'. Consider overriding memory-based 'ReadAsync' to improve performance. +// 'SerialStream' overrides array-based 'WriteAsync' but does not override memory-based 'WriteAsync'. Consider overriding memory-based 'WriteAsync' to improve performance. +#pragma warning disable CA1844 internal sealed partial class SerialStream : Stream +#pragma warning restore CA1844 { private const int MaxDataBits = 8; private const int MinDataBits = 5;