Skip to content

Commit

Permalink
Mark Obsoletions for .NET 5 (#39269)
Browse files Browse the repository at this point in the history
* Mark new obsoletions for .NET 5; update existing obsoletions

* Exclude DirectoryServicesPermission/DirectoryServicesPermissionAttribute from obsoletions for now

* No need to restore SYSLIB0003 at end of Forwards files

* Use a common Obsoletions.cs file for all SYSLIB obsoletions

* Resurrect CER code behind #ifdef in EventSource

* Mark GlobalAssemblyCache overrides as Obsolete

* Suppress Thread.Abort() error in ImageAnimator.Unix.cs

* Unconditionally mark RoAssembly.GlobalAssemblyCache as obsolete

* Rename MSLIB0001 to SYSLIB0001 in ref assembly

* Suppress obsoletion warnings in tests

* Adopt a uniform #ifdef for NET50_OBSOLETIONS

* Fix BinaryFormatter obsoletion message after the rebase

* Use SYSTEM_PRIVATE_CORELIB constant instead of NETCOREAPP

* Remove the code comment on the ifdef

* Apply feedback related to CER obsoletions

* Apply feedback related to CAS

* Update ref assembly to reflect SecurityManager obsoletion

* Fix regression in System.IO.Pipes.NamedPipeServerStream.Windows.RunAsClient
  • Loading branch information
jeffhandley authored Jul 18, 2020
1 parent 87d8f7d commit 329f0db
Show file tree
Hide file tree
Showing 195 changed files with 997 additions and 183 deletions.
24 changes: 16 additions & 8 deletions docs/project/list-of-obsoletions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@ List of Obsoletions

Per https://github.com/dotnet/designs/blob/master/accepted/2020/better-obsoletion/better-obsoletion.md, we now have a strategy in place for marking existing APIs as `[Obsolete]`. This takes advantage of the new diagnostic id and URL template mechanisms introduced to `ObsoleteAttribute` in .NET 5.

When obsoleting an API, use the diagnostic ID `MSLIB####`, where _\#\#\#\#_ is the next four-digit identifier in the sequence, and add it to the list below. This helps us maintain a centralized location of all APIs that were obsoleted using this mechanism.
When obsoleting an API, use the diagnostic ID `SYSLIB####`, where _\#\#\#\#_ is the next four-digit identifier in the sequence, and add it to the list below. This helps us maintain a centralized location of all APIs that were obsoleted using this mechanism.

The URL template we use for obsoletions is `https://aka.ms/dotnet-warnings/{0}`.

Currently the identifiers `MSLIB0001` through `MSLIB0999` are carved out for obsoletions. If we wish to introduce analyzer warnings not related to obsoletion in the future, we should begin at a different range, such as `MSLIB2000`.
Currently the identifiers `SYSLIB0001` through `SYSLIB0999` are carved out for obsoletions. If we wish to introduce analyzer warnings not related to obsoletion in the future, we should begin at a different range, such as `SYSLIB2000`.

## Current obsoletions (`MSLIB0001` - `MSLIB0999`)
## Current obsoletions (`SYSLIB0001` - `SYSLIB0999`)

| Diagnostic ID | Description |
| :--------------- | :---------- |
| __`MSLIB0001`__ | The UTF-7 encoding is insecure and should not be used. Consider using UTF-8 instead. |
| __`MSLIB0002`__ | `PrincipalPermissionAttribute` is not honored by the runtime and must not be used. |
| __`MSLIB0003`__ | `BinaryFormatter` serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for recommended alternatives. |
| Diagnostic ID | Description |
| :---------------- | :---------- |
| __`SYSLIB0001`__ | The UTF-7 encoding is insecure and should not be used. Consider using UTF-8 instead. |
| __`SYSLIB0002`__ | PrincipalPermissionAttribute is not honored by the runtime and must not be used. |
| __`SYSLIB0003`__ | Code Access Security is not supported or honored by the runtime. |
| __`SYSLIB0004`__ | The Constrained Execution Region (CER) feature is not supported. |
| __`SYSLIB0005`__ | The Global Assembly Cache is not supported. |
| __`SYSLIB0006`__ | Thread.Abort is not supported and throws PlatformNotSupportedException. |
| __`SYSLIB0007`__ | The default implementation of this cryptography algorithm is not supported. |
| __`SYSLIB0008`__ | The CreatePdbGenerator API is not supported and throws PlatformNotSupportedException. |
| __`SYSLIB0009`__ | The AuthenticationManager Authenticate and PreAuthenticate methods are not supported and throw PlatformNotSupportedException. |
| __`SYSLIB0010`__ | This Remoting API is not supported and throws PlatformNotSupportedException. |
| __`SYSLIB0011`__ | `BinaryFormatter` serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for recommended alternatives. |
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ public override AssemblyName[] GetReferencedAssemblies()
return InternalAssembly.GetReferencedAssemblies();
}

[Obsolete(Obsoletions.GlobalAssemblyCacheMessage, DiagnosticId = Obsoletions.GlobalAssemblyCacheDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public override bool GlobalAssemblyCache => InternalAssembly.GlobalAssemblyCache;

public override long HostContext => InternalAssembly.HostContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ public override string ImageRuntimeVersion
}
}

[Obsolete(Obsoletions.GlobalAssemblyCacheMessage, DiagnosticId = Obsoletions.GlobalAssemblyCacheDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public override bool GlobalAssemblyCache => false;

public override long HostContext => 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private static bool SafeWaitForMutex(Mutex mutexIn, ref Mutex mutexOut)
private static bool SafeWaitForMutexOnce(Mutex mutexIn, ref Mutex mutexOut)
{
bool ret;
RuntimeHelpers.PrepareConstrainedRegions();

try
{ }
finally
Expand Down
43 changes: 43 additions & 0 deletions src/libraries/Common/src/System/Obsoletions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System
{
internal static class Obsoletions
{
internal const string SharedUrlFormat = "https://aka.ms/dotnet-warnings/{0}";

internal const string SystemTextEncodingUTF7Message = "The UTF-7 encoding is insecure and should not be used. Consider using UTF-8 instead.";
internal const string SystemTextEncodingUTF7DiagId = "SYSLIB0001";

internal const string PrincipalPermissionAttributeMessage = "PrincipalPermissionAttribute is not honored by the runtime and must not be used.";
internal const string PrincipalPermissionAttributeDiagId = "SYSLIB0002";

internal const string CodeAccessSecurityMessage = "Code Access Security is not supported or honored by the runtime.";
internal const string CodeAccessSecurityDiagId = "SYSLIB0003";

internal const string ConstrainedExecutionRegionMessage = "The Constrained Execution Region (CER) feature is not supported.";
internal const string ConstrainedExecutionRegionDiagId = "SYSLIB0004";

internal const string GlobalAssemblyCacheMessage = "The Global Assembly Cache is not supported.";
internal const string GlobalAssemblyCacheDiagId = "SYSLIB0005";

internal const string ThreadAbortMessage = "Thread.Abort is not supported and throws PlatformNotSupportedException.";
internal const string ThreadAbortDiagId = "SYSLIB0006";

internal const string DefaultCryptoAlgorithmsMessage = "The default implementation of this cryptography algorithm is not supported.";
internal const string DefaultCryptoAlgorithmsDiagId = "SYSLIB0007";

internal const string CreatePdbGeneratorMessage = "The CreatePdbGenerator API is not supported and throws PlatformNotSupportedException.";
internal const string CreatePdbGeneratorDiagId = "SYSLIB0008";

internal const string AuthenticationManagerMessage = "The AuthenticationManager Authenticate and PreAuthenticate methods are not supported and throw PlatformNotSupportedException.";
internal const string AuthenticationManagerDiagId = "SYSLIB0009";

internal const string RemotingApisMessage = "This Remoting API is not supported and throws PlatformNotSupportedException.";
internal const string RemotingApisDiagId = "SYSLIB0010";

internal const string BinaryFormatterMessage = "BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.";
internal const string BinaryFormatterDiagId = "SYSLIB0011";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ public static extern VirtualAllocHandle VirtualAlloc(

// https://msdn.microsoft.com/en-us/library/windows/desktop/aa366892(v=vs.85).aspx
[DllImport(KERNEL32_LIB, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool VirtualFree(
[In] IntPtr lpAddress,
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<!-- Warnings that should be disabled in our test projects. -->
<PropertyGroup Condition="'$(IsTestProject)' == 'true' or '$(IsTestSupportProject)' == 'true'">
<!-- don't warn on usage of BinaryFormatter from test projects -->
<NoWarn>$(NoWarn);MSLIB0003</NoWarn>
<NoWarn>$(NoWarn);SYSLIB0011</NoWarn>
</PropertyGroup>

<!-- Common repo directories -->
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<PropertyGroup>
<NoWarn Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' or '$(TargetFrameworkIdentifier)' == '.NETStandard' or '$(TargetFramework)' == 'netcoreapp2.1'">$(NoWarn);nullable</NoWarn>
<NoWarn Condition="'$(GeneratePlatformNotSupportedAssembly)' == 'true' or '$(GeneratePlatformNotSupportedAssemblyMessage)' != ''">$(NoWarn);nullable</NoWarn>
<!-- Ignore Obsolete errors within the generated shims that type-forward types.
SYSLIB0003 is for CAS. SYSLIB0004 is the obsoletion of CER. -->
<NoWarn Condition="'$(IsPartialFacadeAssembly)' == 'true'">$(NoWarn);SYSLIB0003;SYSLIB0004</NoWarn>
<!-- Reset these properties back to blank, since they are defaulted by Microsoft.NET.Sdk -->
<FileAlignment Condition="'$(FileAlignment)' == '512'" />
<ErrorReport Condition="'$(ErrorReport)' == 'prompt'" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
</PropertyGroup>
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
<!-- Constrained Execution Regions only apply to netstandard2.0 and net4* -->
<DefineConstants Condition="$(TargetFramework.StartsWith('netstandard2.0')) or $(TargetFramework.StartsWith('net4'))">$(DefineConstants);FEATURE_CER</DefineConstants>
<IsPartialFacadeAssembly Condition="$(TargetFramework.StartsWith('net4'))">true</IsPartialFacadeAssembly>
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetFramework)' == 'netstandard2.0' and '$(TargetsAnyOS)' == 'true'">SR.PlatformNotSupported_SystemEvents</GeneratePlatformNotSupportedAssemblyMessage>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,9 @@ private static void Shutdown()
}
}

#if FEATURE_CER
[PrePrepareMethod]
#endif
private static void Shutdown(object? sender, EventArgs e)
{
Shutdown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ private DesigntimeLicenseContextSerializer()
public static void Serialize(Stream o, string cryptoKey, DesigntimeLicenseContext context)
{
IFormatter formatter = new BinaryFormatter();
#pragma warning disable MSLIB0003 // Issue https://github.com/dotnet/runtime/issues/39293 tracks finding an alternative to BinaryFormatter
#pragma warning disable SYSLIB0011 // Issue https://github.com/dotnet/runtime/issues/39293 tracks finding an alternative to BinaryFormatter
formatter.Serialize(o, new object[] { cryptoKey, context._savedLicenseKeys });
#pragma warning restore MSLIB0003
#pragma warning restore SYSLIB0011
}

internal static void Deserialize(Stream o, string cryptoKey, RuntimeLicenseContext context)
{
#pragma warning disable MSLIB0003 // Issue https://github.com/dotnet/runtime/issues/39293 tracks finding an alternative to BinaryFormatter
#pragma warning disable SYSLIB0011 // Issue https://github.com/dotnet/runtime/issues/39293 tracks finding an alternative to BinaryFormatter
IFormatter formatter = new BinaryFormatter();

object obj = formatter.Deserialize(o);
#pragma warning restore MSLIB0003
#pragma warning restore SYSLIB0011

if (obj is object[] value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,12 @@ bool IInternalConfigHost.IsTrustedConfigPath(string configPath)
throw new NotImplementedException();
}

#pragma warning disable SYSLIB0003 // Obsolete: CAS
void IInternalConfigHost.GetRestrictedPermissions(IInternalConfigRecord configRecord, out PermissionSet permissionSet, out bool isHostReady)
{
throw new NotImplementedException();
}
#pragma warning restore SYSLIB0003 // Obsolete: CAS
}
}
}
8 changes: 4 additions & 4 deletions src/libraries/System.Data.Common/src/System/Data/DataSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ private void SerializeDataSet(SerializationInfo info, StreamingContext context,
{
BinaryFormatter bf = new BinaryFormatter(null, new StreamingContext(context.State, false));
MemoryStream memStream = new MemoryStream();
#pragma warning disable MSLIB0003 // Issue https://github.com/dotnet/runtime/issues/39289 tracks finding an alternative to BinaryFormatter
#pragma warning disable SYSLIB0011 // Issue https://github.com/dotnet/runtime/issues/39289 tracks finding an alternative to BinaryFormatter
bf.Serialize(memStream, Tables[i]);
#pragma warning restore MSLIB0003
#pragma warning restore SYSLIB0011
memStream.Position = 0;
info.AddValue(string.Format(CultureInfo.InvariantCulture, "DataSet.Tables_{0}", i), memStream.GetBuffer());
}
Expand Down Expand Up @@ -384,9 +384,9 @@ private void DeserializeDataSetSchema(SerializationInfo info, StreamingContext c
MemoryStream memStream = new MemoryStream(buffer);
memStream.Position = 0;
BinaryFormatter bf = new BinaryFormatter(null, new StreamingContext(context.State, false));
#pragma warning disable MSLIB0003 // Issue https://github.com/dotnet/runtime/issues/39289 tracks finding an alternative to BinaryFormatter
#pragma warning disable SYSLIB0011 // Issue https://github.com/dotnet/runtime/issues/39289 tracks finding an alternative to BinaryFormatter
DataTable dt = (DataTable)bf.Deserialize(memStream);
#pragma warning restore MSLIB0003
#pragma warning restore SYSLIB0011
Tables.Add(dt);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,6 @@ internal static int StringLength(string inputString)
return ((null != inputString) ? inputString.Length : 0);
}

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
internal static IntPtr IntPtrOffset(IntPtr pbase, int offset)
{
if (4 == ADP.PtrSize)
Expand Down
Loading

0 comments on commit 329f0db

Please sign in to comment.