* remove SYSLIB0004 warnings by removing obsolete API calls

* Remove SYSLIB0005 warnings by removing calls to GAC

* Remove SYSLIB0028 warning by replacing call to privatekey by GetRSAPrivateKey

* Remove warning SYSLIB0005 for file common with NETFX

* Removing SYSLIB0003  warnings

* Revert "Removing SYSLIB0003  warnings"

This reverts commit e1cd499f1d.

* Reverting because of build fail

* Fixing build failure due to CER

* Fixing as per review comments

* Fix as per review comments to throw exception.

* Throwing exception when privatekey is null.

* Modify C++/CLI files for warnings.

* PR feedback

* Undo replacement of x509Certificate2.PrivateKey until RC2
This commit is contained in:
Ashish Kumar Singh 2021-08-18 06:04:10 +05:30 коммит произвёл GitHub
Родитель 55559850eb
Коммит 07edfec90d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
20 изменённых файлов: 21 добавлений и 140 удалений

Просмотреть файл

@ -92,9 +92,6 @@ namespace MS { namespace Internal { namespace Text { namespace TextInterface
_pFactory = (IDWriteFactory*)factoryTemp;
}
#pragma warning (disable : 4950) // The Constrained Execution Region (CER) feature is not supported.
[ReliabilityContract(Consistency::WillNotCorruptState, Cer::Success)]
#pragma warning (default : 4950) // The Constrained Execution Region (CER) feature is not supported.
__declspec(noinline) bool Factory::ReleaseHandle()
{
if (_wpfFontCollectionLoader != nullptr)

Просмотреть файл

@ -79,9 +79,6 @@ namespace MS { namespace Internal { namespace Text { namespace TextInterface
protected:
#pragma warning (disable : 4950) // The Constrained Execution Region (CER) feature is not supported.
[ReliabilityContract(Consistency::WillNotCorruptState, Cer::Success)]
#pragma warning (default : 4950) // The Constrained Execution Region (CER) feature is not supported.
virtual bool ReleaseHandle() override;
internal:

Просмотреть файл

@ -19,10 +19,7 @@ namespace MS { namespace Internal { namespace Text { namespace TextInterface { n
NativePointerCriticalHandle(void* pNativePointer);
virtual property bool IsInvalid
{
#pragma warning (disable : 4950) // The Constrained Execution Region (CER) feature is not supported.
[ReliabilityContract(Consistency::WillNotCorruptState, Cer::Success)]
#pragma warning (default : 4950) // The Constrained Execution Region (CER) feature is not supported.
{
bool get() override;
}

Просмотреть файл

@ -84,19 +84,13 @@ namespace MS.Win32.Recognizer
// Do not provide a finalizer - SafeHandle's critical finalizer will
// call ReleaseHandle for you.
public override bool IsInvalid
{
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
{
get
{
return IsClosed || handle == IntPtr.Zero;
}
}
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
override protected bool ReleaseHandle()
{
Debug.Assert(handle != IntPtr.Zero);
@ -126,19 +120,12 @@ namespace MS.Win32.Recognizer
// call ReleaseHandle for you.
public override bool IsInvalid
{
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
get
{
return IsClosed || handle == IntPtr.Zero;
}
}
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
override protected bool ReleaseHandle()
{
//Note: It is not an error to have already called DestroyRecognizer

Просмотреть файл

@ -524,9 +524,7 @@ namespace MS.Win32.PresentationCore
[DllImport(DllImport.MilCore, EntryPoint = "MILAddRef")]
internal static extern UInt32 AddRef(SafeReversePInvokeWrapper pIUnknown);
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[DllImport(DllImport.MilCore, EntryPoint = "MILRelease"), ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[DllImport(DllImport.MilCore, EntryPoint = "MILRelease")]
internal static extern int Release(IntPtr pIUnkown);

Просмотреть файл

@ -37,40 +37,7 @@ namespace MS.Internal
internal void FilterCallback(Object sender, AssemblyLoadEventArgs args)
{
// This code is reentrant
lock (_lock)
{
// Extract assembly
Assembly a = args.LoadedAssembly;
// xmlns cache loads assemblies as reflection only and we cannot inspect these using the code below
// so we ignore also keeping this first is super important because the first time cost is really high
// other wise also we cannot do any processing on a reflection only assembly aside from reflection based actions
if (!a.ReflectionOnly)
{
// check if it is in the Gac , this ensures that we eliminate any non GAC assembly which are of no risk
#pragma warning disable SYSLIB0005 // 'Assembly.GlobalAssemblyCache' is obsolete.
if (a.GlobalAssemblyCache)
#pragma warning restore SYSLIB0005 // 'Assembly.GlobalAssemblyCache' is obsolete.
{
string assemblyName = AssemblyNameWithFileVersion(a);
// If we are on the disallowed list kill the application domain
if (AssemblyOnDisallowedList(assemblyName))
{
// Kill the application domain
UnsafeNativeMethods.ProcessUnhandledException_DLL(SR.Get(SRID.KillBitEnforcedShutdown) + assemblyName);
// I want to ensure that the process really dies
try
{
System.Environment.Exit(-1);
}
finally
{
Debug.Fail("Environment.Exit() failed.");
}
}
}
}
}
/* This method no longer applies to .NET Core and should be removed. */
}
//appends assembly name with file version to generate a unique entry for the assembly lookup process

Просмотреть файл

@ -252,9 +252,7 @@ namespace MS.Internal.AppModel
// We do not care about assemblies loaded into the reflection-only context or the Gaced assemblies.
// For example, in Sparkle whenever a project is built all dependent assemblies will be loaded reflection only.
// We do no care about those. Only when a assembly is loaded into the execution context, we will need to update the cache.
#pragma warning disable SYSLIB0005 // 'Assembly.GlobalAssemblyCache' is obsolete.
if ((!assembly.ReflectionOnly) && (!assembly.GlobalAssemblyCache))
#pragma warning restore SYSLIB0005 // 'Assembly.GlobalAssemblyCache' is obsolete.
if ((!assembly.ReflectionOnly))
{
AssemblyName assemblyInfo = new AssemblyName(assembly.FullName);

Просмотреть файл

@ -229,9 +229,11 @@ namespace System.Windows.Markup
// so they can be loaded again. The is the Dev build/load/build/load
// Designer scenario. (Don't mess with GACed assemblies)
Assembly assem = ReflectionHelper.GetAlreadyLoadedAssembly(asmName);
#pragma warning disable SYSLIB0005 // 'Assembly.GlobalAssemblyCache' is obsolete.
if (assem != null && !assem.GlobalAssemblyCache)
#pragma warning restore SYSLIB0005 // 'Assembly.GlobalAssemblyCache' is obsolete.
if (assem != null
#if NETFX
&& !assem.GlobalAssemblyCache
#endif
)
{
ReflectionHelper.ResetCacheForAssembly(asmName);
// No way to reset SchemaContext at assembly granularity, so just reset the whole context

Просмотреть файл

@ -1389,9 +1389,6 @@ namespace Standard
private SafeDC() : base(true) { }
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
protected override bool ReleaseHandle()
{
if (_created)
@ -1514,9 +1511,6 @@ namespace Standard
{
private SafeHBITMAP() : base(true) { }
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
protected override bool ReleaseHandle()
{
return NativeMethods.DeleteObject(handle);
@ -1527,9 +1521,6 @@ namespace Standard
{
private SafeGdiplusStartupToken() : base(true) { }
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
protected override bool ReleaseHandle()
{
Status s = NativeMethods.GdiplusShutdown(this.handle);
@ -1598,9 +1589,7 @@ namespace Standard
}
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
protected override bool ReleaseHandle()
{
try
@ -2665,9 +2654,7 @@ namespace Standard
[SuppressMessage("Mricrosoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
[DllImport("kernel32.dll")]
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool FindClose(IntPtr handle);

Просмотреть файл

@ -75,9 +75,7 @@ namespace MS.Internal.Printing.Configuration
/// <param name="handle">device handle proxy has been bound to</param>
/// <returns>HRESULT code</returns>
[DllImport(DllImport.PrntvPt, EntryPoint = "PTCloseProvider", CharSet = CharSet.Unicode, ExactSpelling = true)]
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
public static extern uint PTCloseProviderImpl(IntPtr handle);
/// <summary>

Просмотреть файл

@ -399,9 +399,7 @@ namespace MS.Internal.Printing.Configuration
CultureInfo.InvariantCulture,
DeviceNamespaceFormat,
BuildInfo.WCP_VERSION_SUFFIX,
#pragma warning disable SYSLIB0013
Uri.EscapeUriString(this._driverName),
#pragma warning restore SYSLIB0013
Uri.EscapeDataString(this._driverName),
this._driverVersion);
}

Просмотреть файл

@ -299,9 +299,7 @@ namespace MS.Internal
/// <summary>
/// Wait for a set of handles.
/// </summary>
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[PrePrepareMethod]
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
public override int Wait(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout)
{
return MS.Win32.UnsafeNativeMethods.WaitForMultipleObjectsEx(waitHandles.Length, waitHandles, waitAll, millisecondsTimeout, false);

Просмотреть файл

@ -258,9 +258,7 @@ namespace MS.Win32
private BitmapHandle(bool ownsHandle) : base(ownsHandle, NativeMethods.CommonHandles.GDI)
{
}
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
protected override bool ReleaseHandle()
{
return UnsafeNativeMethods.DeleteObject(handle);
@ -285,10 +283,7 @@ namespace MS.Win32
private IconHandle() : base(true, NativeMethods.CommonHandles.Icon)
{
}
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
protected override bool ReleaseHandle()
{
return UnsafeNativeMethods.DestroyIcon(handle);
@ -314,9 +309,6 @@ namespace MS.Win32
{
}
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
protected override bool ReleaseHandle()
{
return UnsafeNativeMethods.DestroyCursor( handle );
@ -594,9 +586,6 @@ namespace MS.Win32
return (LocalFree(base.handle) == IntPtr.Zero);
}
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[DllImport("kernel32.dll")]
private static extern IntPtr LocalFree(IntPtr hMem);
}

Просмотреть файл

@ -170,9 +170,7 @@ namespace MS.Win32
/// </summary>
/// <param name="hMem"></param>
/// <returns></returns>
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[DllImport(ExternDll.Kernel32, SetLastError = true), ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[DllImport(ExternDll.Kernel32, SetLastError = true)]
internal static extern IntPtr LocalFree(IntPtr hMem);
#if BASE_NATIVEMETHODS
@ -638,9 +636,7 @@ namespace MS.Win32
}
}
[DllImport(ExternDll.User32, EntryPoint = "GetIconInfo", CharSet = CharSet.Auto, SetLastError = true)]
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
private static extern bool GetIconInfoImpl(HandleRef hIcon, [Out] ICONINFO_IMPL piconinfo);
[StructLayout(LayoutKind.Sequential)]
@ -664,9 +660,6 @@ namespace MS.Win32
piconinfo = new NativeMethods.ICONINFO();
ICONINFO_IMPL iconInfoImpl = new ICONINFO_IMPL();
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
SRCS.RuntimeHelpers.PrepareConstrainedRegions(); // Mark the following as special
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
try
{
// Intentionally empty

Просмотреть файл

@ -2,9 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// Turn off CER warnings: The Constrained Execution Region (CER) feature is not supported.
#pragma warning (disable : 4950)
#ifndef GDIEXPORTER
#define GDIEXPORTER
@ -101,12 +98,10 @@ public:
property bool IsInvalid
{
[ReliabilityContract(Consistency::WillNotCorruptState, Cer::Success)]
bool virtual get() override { return IsClosed || (handle == IntPtr::Zero); }
}
protected:
[ReliabilityContract(Consistency::WillNotCorruptState, Cer::Success)]
bool virtual ReleaseHandle() override
{
IntPtr tempHandle = handle;
@ -140,7 +135,6 @@ public:
#endif
protected:
[ReliabilityContract(Consistency::WillNotCorruptState, Cer::Success)]
bool virtual ReleaseHandle() override
{
IntPtr tempHandle = handle;
@ -168,7 +162,6 @@ public:
property bool IsInvalid
{
[ReliabilityContract(Consistency::WillNotCorruptState, Cer::Success)]
bool virtual get() override { return IsClosed || (handle == IntPtr::Zero); }
}
@ -181,7 +174,6 @@ public:
}
protected:
[ReliabilityContract(Consistency::WillNotCorruptState, Cer::Success)]
bool virtual ReleaseHandle() override
{
IntPtr tempHandle = handle;

Просмотреть файл

@ -503,9 +503,6 @@ namespace MS.Internal.Automation
}
else
{
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
RuntimeHelpers.PrepareConstrainedRegions();
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
bool fRelease = false;
try
{

Просмотреть файл

@ -44,9 +44,6 @@ namespace System.Windows.Automation
SafeConditionMemoryHandle sh = new SafeConditionMemoryHandle();
int size = Marshal.SizeOf(uiaCondition);
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
RuntimeHelpers.PrepareConstrainedRegions(); // ensures that the following finally block is atomic
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
try { }
finally
{
@ -66,9 +63,6 @@ namespace System.Windows.Automation
int intPtrSize = Marshal.SizeOf(typeof(IntPtr));
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
RuntimeHelpers.PrepareConstrainedRegions(); // ensures that the following finally block is atomic
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
try { }
finally
{

Просмотреть файл

@ -995,9 +995,6 @@ namespace MS.Internal.AutomationProxies
}
else
{
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
RuntimeHelpers.PrepareConstrainedRegions();
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
bool fRelease = false;
try
{

Просмотреть файл

@ -89,9 +89,6 @@ namespace System.Windows.Threading
/// <summary>
/// Wait for a set of handles.
/// </summary>
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[PrePrepareMethod]
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
public override int Wait(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout)
{
if(_dispatcher._disableProcessingCount > 0)

Просмотреть файл

@ -52,9 +52,7 @@ namespace MS.Win32
}
[DllImport(ExternDll.Gdi32, ExactSpelling = true, CharSet = CharSet.Auto)]
#pragma warning disable SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
#pragma warning restore SYSLIB0004 // The Constrained Execution Region (CER) feature is not supported.
[ResourceExposure(ResourceScope.None)]
public static extern bool DeleteDC(IntPtr hDC);
}