Skip to content

Commit

Permalink
Improve some of our recent obsoletions (dotnet#51721)
Browse files Browse the repository at this point in the history
* Replace usage of NET50_OBSOLETIONS with NET5_0_OR_GREATER

* Correct GitHub handle

* Use a diagnostic id for the RuntimeEnvironment obsoletions from dotnet#50666

* Use fully-qualified attribute name in ref source updates from dotnet#49411

* Use a diagnostic id for the JsonSerializerOptions.IgnoreNullValues obsoletion from dotnet#41141
  • Loading branch information
jeffhandley authored Apr 23, 2021
1 parent 23d16da commit ac98c81
Show file tree
Hide file tree
Showing 134 changed files with 299 additions and 303 deletions.
4 changes: 3 additions & 1 deletion docs/project/list-of-diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The acceptance criteria for adding an obsoletion includes:
* Register the `SYSLIB0###` URL in `aka.ms`
* The vanity name will be `dotnet-warnings/syslib0###`
* Ensure the link's group owner matches the group owner of `dotnet-warnings/syslib0001`
* Connect with `@jeffhandley`, `@levib`, or `@gewarren` with any questions
* Connect with `@jeffhandley`, `@GrabYourPitchforks`, or `@gewarren` with any questions

An example obsoletion PR that can be referenced where each of the above criteria was met is:

Expand Down Expand Up @@ -66,6 +66,8 @@ The PR that reveals the implementation of the `<IncludeInternalObsoleteAttribute
| __`SYSLIB0014`__ | WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead. |
| __`SYSLIB0015`__ | DisablePrivateReflectionAttribute has no effect in .NET 6.0+ applications. |
| __`SYSLIB0016`__ | Use the Graphics.GetContextInfo overloads that accept arguments for better performance and fewer allocations. |
| __`SYSLIB0019`__ | RuntimeEnvironment members SystemConfigurationFile, GetRuntimeInterfaceAsIntPtr, and GetRuntimeInterfaceAsObject are no longer supported and throw PlatformNotSupportedException. |
| __`SYSLIB0020`__ | JsonSerializerOptions.IgnoreNullValues is obsolete. To ignore null values when serializing, set DefaultIgnoreCondition to JsonIgnoreCondition.WhenWritingNull. |

## Analyzer Warnings

Expand Down
6 changes: 6 additions & 0 deletions src/libraries/Common/src/System/Obsoletions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,11 @@ internal static class Obsoletions

internal const string GetContextInfoMessage = "Use the Graphics.GetContextInfo overloads that accept arguments for better performance and fewer allocations.";
internal const string GetContextInfoDiagId = "SYSLIB0016";

internal const string RuntimeEnvironmentMessage = "RuntimeEnvironment members SystemConfigurationFile, GetRuntimeInterfaceAsIntPtr, and GetRuntimeInterfaceAsObject are no longer supported and throw PlatformNotSupportedException.";
internal const string RuntimeEnvironmentDiagId = "SYSLIB0019";

internal const string JsonSerializerOptionsIgnoreNullValuesMessage = "JsonSerializerOptions.IgnoreNullValues is obsolete. To ignore null values when serializing, set DefaultIgnoreCondition to JsonIgnoreCondition.WhenWritingNull.";
internal const string JsonSerializerOptionsIgnoreNullValuesDiagId = "SYSLIB0020";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
<Nullable>enable</Nullable>
</PropertyGroup>
<!-- We conditionally apply net5.0+ obsoletions -->
<PropertyGroup Condition="!($(TargetFramework.StartsWith('netcoreapp')) or $(TargetFramework.StartsWith('netstandard')) or $(TargetFramework.StartsWith('net4')))">
<DefineConstants>$(DefineConstants);NET50_OBSOLETIONS</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="System\CoreRtBridge.cs" />
<Compile Include="System\Reflection\DefaultBinder.cs" />
Expand Down Expand Up @@ -164,7 +160,7 @@
<PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.CompilerServices.Unsafe\src\System.Runtime.CompilerServices.Unsafe.ilproj" />
</ItemGroup>

<!-- Application tfms (.NETCoreApp, .NETFramework) need to use the same or higher version of .NETStandard's dependencies. -->
<Choose>
<When Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ protected RoAssembly(MetadataLoadContext loader, int assemblyFileCount)

// Location and codebase
public abstract override string Location { get; }
#if NET50_OBSOLETIONS
#if NET5_0_OR_GREATER
[Obsolete(Obsoletions.CodeBaseMessage, DiagnosticId = Obsoletions.CodeBaseDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
#endif
public sealed override string CodeBase => throw new NotSupportedException(SR.NotSupported_AssemblyCodeBase);
#if NET50_OBSOLETIONS
#if NET5_0_OR_GREATER
[Obsolete(Obsoletions.CodeBaseMessage, DiagnosticId = Obsoletions.CodeBaseDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
#endif
public sealed override string EscapedCodeBase => throw new NotSupportedException(SR.NotSupported_AssemblyCodeBase);
Expand Down Expand Up @@ -151,7 +151,7 @@ public sealed override AssemblyName[] GetReferencedAssemblies()

// Miscellaneous properties
public sealed override bool ReflectionOnly => true;
#if NET50_OBSOLETIONS
#if NET5_0_OR_GREATER
[Obsolete("The Global Assembly Cache is not supported.", DiagnosticId = "SYSLIB0005", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
#endif
public sealed override bool GlobalAssemblyCache => false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -794,13 +794,13 @@ public ProgIdAttribute(string progId) { }
}
public static partial class RuntimeEnvironment
{
[System.ObsoleteAttribute("SystemConfigurationFile is no longer supported.")]
[System.ObsoleteAttribute("RuntimeEnvironment members SystemConfigurationFile, GetRuntimeInterfaceAsIntPtr, and GetRuntimeInterfaceAsObject are no longer supported and throw PlatformNotSupportedException.", DiagnosticId = "SYSLIB0019", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public static string SystemConfigurationFile { get { throw null; } }
public static bool FromGlobalAccessCache(System.Reflection.Assembly a) { throw null; }
public static string GetRuntimeDirectory() { throw null; }
[System.ObsoleteAttribute("GetRuntimeInterfaceAsIntPtr(Guid, Guid) is no longer supported.")]
[System.ObsoleteAttribute("RuntimeEnvironment members SystemConfigurationFile, GetRuntimeInterfaceAsIntPtr, and GetRuntimeInterfaceAsObject are no longer supported and throw PlatformNotSupportedException.", DiagnosticId = "SYSLIB0019", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public static System.IntPtr GetRuntimeInterfaceAsIntPtr(System.Guid clsid, System.Guid riid) { throw null; }
[System.ObsoleteAttribute("GetRuntimeInterfaceAsObject(Guid, Guid) is no longer supported.")]
[System.ObsoleteAttribute("RuntimeEnvironment members SystemConfigurationFile, GetRuntimeInterfaceAsIntPtr, and GetRuntimeInterfaceAsObject are no longer supported and throw PlatformNotSupportedException.", DiagnosticId = "SYSLIB0019", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public static object GetRuntimeInterfaceAsObject(System.Guid clsid, System.Guid riid) { throw null; }
public static string GetSystemVersion() { throw null; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<Compile Include="System\Runtime\InteropServices\TypeLibVarFlags.cs" />
<Compile Include="System\Runtime\InteropServices\TypeLibVersionAttribute.cs" />
<Compile Include="System\Security\SecureStringMarshal.cs" />
<Compile Include="$(CommonPath)System\Obsoletions.cs" Link="Common\System\Obsoletions.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(CoreLibProject)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace System.Runtime.InteropServices
{
public static class RuntimeEnvironment
{
[Obsolete("SystemConfigurationFile is no longer supported.")]
[Obsolete(Obsoletions.RuntimeEnvironmentMessage, DiagnosticId = Obsoletions.RuntimeEnvironmentDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public static string SystemConfigurationFile => throw new PlatformNotSupportedException();

public static bool FromGlobalAccessCache(Assembly a) => false;
Expand All @@ -23,10 +23,10 @@ public static string GetRuntimeDirectory()
return Path.GetDirectoryName(runtimeDirectory) + Path.DirectorySeparatorChar;
}

[Obsolete("GetRuntimeInterfaceAsIntPtr(Guid, Guid) is no longer supported.")]
[Obsolete(Obsoletions.RuntimeEnvironmentMessage, DiagnosticId = Obsoletions.RuntimeEnvironmentDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public static IntPtr GetRuntimeInterfaceAsIntPtr(Guid clsid, Guid riid) => throw new PlatformNotSupportedException();

[Obsolete("GetRuntimeInterfaceAsObject(Guid, Guid) is no longer supported.")]
[Obsolete(Obsoletions.RuntimeEnvironmentMessage, DiagnosticId = Obsoletions.RuntimeEnvironmentDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public static object GetRuntimeInterfaceAsObject(Guid clsid, Guid riid) => throw new PlatformNotSupportedException();

public static string GetSystemVersion() => typeof(object).Assembly.ImageRuntimeVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,25 @@ public void RuntimeEnvironmentSysVersion()
Assert.NotEmpty(RuntimeEnvironment.GetSystemVersion());
}

#pragma warning disable SYSLIB0019 // RuntimeEnvironment members SystemConfigurationFile, GetRuntimeInterfaceAsIntPtr, and GetRuntimeInterfaceAsObject are no longer supported and throw PlatformNotSupportedException.
[Fact]
public void SystemConfigurationFile_Get_ThrowsPlatformNotSupportedException()
{
#pragma warning disable 618 // SystemConfigurationFile is marked as Obsolete
Assert.Throws<PlatformNotSupportedException>(() => RuntimeEnvironment.SystemConfigurationFile);
#pragma warning restore 618
}

[Fact]
public void GetRuntimeInterfaceAsObject_Invoke_ThrowsPlatformNotSupportedException()
{
#pragma warning disable 618 // GetRuntimeInterfaceAsObject is marked as Obsolete
Assert.Throws<PlatformNotSupportedException>(() => RuntimeEnvironment.GetRuntimeInterfaceAsObject(Guid.Empty, Guid.Empty));
#pragma warning restore 618
}

[Fact]
public void GetRuntimeInterfaceAsIntPtr_Invoke_ThrowsPlatformNotSupportedException()
{
#pragma warning disable 618 // GetRuntimeInterfaceAsIntPtr is marked as Obsolete
Assert.Throws<PlatformNotSupportedException>(() => RuntimeEnvironment.GetRuntimeInterfaceAsIntPtr(Guid.Empty, Guid.Empty));
#pragma warning restore 618
}
#pragma warning restore SYSLIB0019

[Fact]
public void FromGlobalAccessCache_nNvoke_ReturnsFalse()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,29 +536,29 @@ namespace System.Security.Policy
public sealed partial class Evidence : System.Collections.ICollection, System.Collections.IEnumerable
{
public Evidence() { }
[Obsolete("This constructor is obsolete. Please use the constructor which takes arrays of EvidenceBase instead.")]
[System.ObsoleteAttribute("This constructor is obsolete. Please use the constructor which takes arrays of EvidenceBase instead.")]
public Evidence(object[] hostEvidence, object[] assemblyEvidence) { }
public Evidence(System.Security.Policy.Evidence evidence) { }
public Evidence(System.Security.Policy.EvidenceBase[] hostEvidence, System.Security.Policy.EvidenceBase[] assemblyEvidence) { }
[Obsolete("Evidence should not be treated as an ICollection. Please use GetHostEnumerator and GetAssemblyEnumerator to iterate over the evidence to collect a count.")]
[System.ObsoleteAttribute("Evidence should not be treated as an ICollection. Please use GetHostEnumerator and GetAssemblyEnumerator to iterate over the evidence to collect a count.")]
public int Count { get { throw null; } }
public bool IsReadOnly { get { throw null; } }
public bool IsSynchronized { get { throw null; } }
public bool Locked { get { throw null; } set { } }
public object SyncRoot { get { throw null; } }
[Obsolete("This method is obsolete. Please use AddAssemblyEvidence instead.")]
[System.ObsoleteAttribute("This method is obsolete. Please use AddAssemblyEvidence instead.")]
public void AddAssembly(object id) { }
public void AddAssemblyEvidence<T>(T evidence) where T : System.Security.Policy.EvidenceBase { }
[Obsolete("This method is obsolete. Please use AddHostEvidence instead.")]
[System.ObsoleteAttribute("This method is obsolete. Please use AddHostEvidence instead.")]
public void AddHost(object id) { }
public void AddHostEvidence<T>(T evidence) where T : System.Security.Policy.EvidenceBase { }
public void Clear() { }
public System.Security.Policy.Evidence? Clone() { throw null; }
[Obsolete("Evidence should not be treated as an ICollection. Please use the GetHostEnumerator and GetAssemblyEnumerator methods rather than using CopyTo.")]
[System.ObsoleteAttribute("Evidence should not be treated as an ICollection. Please use the GetHostEnumerator and GetAssemblyEnumerator methods rather than using CopyTo.")]
public void CopyTo(System.Array array, int index) { }
public System.Collections.IEnumerator GetAssemblyEnumerator() { throw null; }
public T? GetAssemblyEvidence<T>() where T : System.Security.Policy.EvidenceBase { throw null; }
[Obsolete("GetEnumerator is obsolete. Please use GetAssemblyEnumerator and GetHostEnumerator instead.")]
public T? GetAssemblyEvidence<T>() where T : System.Security.Policy.EvidenceBase { throw null; }
[System.ObsoleteAttribute("GetEnumerator is obsolete. Please use GetAssemblyEnumerator and GetHostEnumerator instead.")]
public System.Collections.IEnumerator GetEnumerator() { throw null; }
public System.Collections.IEnumerator GetHostEnumerator() { throw null; }
public T? GetHostEvidence<T>() where T : System.Security.Policy.EvidenceBase { throw null; }
Expand Down
Loading

0 comments on commit ac98c81

Please sign in to comment.