Skip to content

Commit

Permalink
Obsolete thumbtacked AssemblyName properties (#59522)
Browse files Browse the repository at this point in the history
* Obsolete thumbtacked AssemblyName properties

Fix #59061

* Ignore obsoletion

* Fix pragma

* Merge the AssemblyName member obsoletions into a single diagnostic id

* Fix pragma to use updated diagnostic id

* Suppress SYSLIB0037 in reflection tests

* Suppress SYSLIB0037 warnings

Co-authored-by: Jeff Handley <jeffhandley@users.noreply.github.com>
Co-authored-by: Jeff Handley <jeff.handley@microsoft.com>
  • Loading branch information
3 people authored Nov 16, 2021
1 parent 25da88c commit e10532a
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/project/list-of-diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ The PR that reveals the implementation of the `<IncludeInternalObsoleteAttribute
| __`SYSLIB0034`__ | CmsSigner(CspParameters) is obsolete and is not supported. Use an alternative constructor instead. |
| __`SYSLIB0035`__ | ComputeCounterSignature without specifying a CmsSigner is obsolete and is not supported. Use the overload that accepts a CmsSigner. |
| __`SYSLIB0036`__ | Regex.CompileToAssembly is obsolete and not supported. Use RegexGeneratorAttribute with the regular expression source generator instead. |
| __`SYSLIB0037`__ | AssemblyName members HashAlgorithm, ProcessorArchitecture, and VersionCompatibility are obsolete and not supported. |

## Analyzer Warnings

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ internal static AssemblyName GetFileInformationCore(string assemblyFile)

internal void SetProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm)
{
#pragma warning disable SYSLIB0037 // AssemblyName.ProcessorArchitecture is obsolete
ProcessorArchitecture = CalculateProcArchIndex(pek, ifm, _flags);
#pragma warning restore SYSLIB0037
}

internal static ProcessorArchitecture CalculateProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm, AssemblyNameFlags flags)
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/Common/src/System/Obsoletions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,8 @@ internal static class Obsoletions

internal const string RegexCompileToAssemblyMessage = "Regex.CompileToAssembly is obsolete and not supported. Use RegexGeneratorAttribute with the regular expression source generator instead.";
internal const string RegexCompileToAssemblyDiagId = "SYSLIB0036";

internal const string AssemblyNameMembersMessage = "AssemblyName members HashAlgorithm, ProcessorArchitecture, and VersionCompatibility are obsolete and not supported.";
internal const string AssemblyNameMembersDiagId = "SYSLIB0037";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public string? EscapedCodeBase
}
}

[Obsolete(Obsoletions.AssemblyNameMembersMessage, DiagnosticId = Obsoletions.AssemblyNameMembersDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public ProcessorArchitecture ProcessorArchitecture
{
get
Expand Down Expand Up @@ -189,12 +190,14 @@ public AssemblyNameFlags Flags
}
}

[Obsolete(Obsoletions.AssemblyNameMembersMessage, DiagnosticId = Obsoletions.AssemblyNameMembersDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public AssemblyHashAlgorithm HashAlgorithm
{
get => _hashAlgorithm;
set => _hashAlgorithm = value;
}

[Obsolete(Obsoletions.AssemblyNameMembersMessage, DiagnosticId = Obsoletions.AssemblyNameMembersDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public AssemblyVersionCompatibility VersionCompatibility
{
get => _versionCompatibility;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ internal AssemblyName GetAssemblyName(StringHandle nameHandle, Version version,
{
Version = version,
CultureName = cultureName,
#pragma warning disable SYSLIB0037 // AssemblyName.HashAlgorithm is obsolete
HashAlgorithm = hashAlgorithm,
#pragma warning restore
Flags = GetAssemblyNameFlags(flags),
ContentType = GetContentTypeFromAssemblyFlags(flags)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ExternallyShipping>false</ExternallyShipping>
<NoWarn>436</NoWarn> <!-- Type conflicts on "Interop" due to InternalsVisibleTo access -->
<!-- 436: Type conflicts on "Interop" due to InternalsVisibleTo access
SYSLIB0037: AssemblyName members HashAlgorithm, ProcessorArchitecture, and VersionCompatibility are obsolete. -->
<NoWarn>$(NoWarn);436;SYSLIB0037</NoWarn>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetFrameworkMinimum)</TargetFrameworks>
<EnableDllImportGenerator>true</EnableDllImportGenerator>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ public AssemblyName CreateAssemblyName()
Version = Version,
CultureName = CultureName,
ContentType = ContentType,
#pragma warning disable SYSLIB0037 // AssemblyName members HashAlgorithm and ProcessorArchitecture are obsolete
HashAlgorithm = HashAlgorithm,
ProcessorArchitecture = ProcessorArchitecture
#pragma warning restore
};

// Yes, *we* have to clone the array. AssemblyName.SetPublicKey() violates framework guidelines and doesn't make a copy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetFrameworkMinimum)</TargetFrameworks>
<!-- The GAC is obsolete, but there are unit tests still referencing it -->
<NoWarn>$(NoWarn);SYSLIB0005</NoWarn>
<!-- SYSLIB0005: The GAC is obsolete, but there are unit tests still referencing it.
SYSLIB0037: AssemblyName members HashAlgorithm, ProcessorArchitecture, and VersionCompatibility are obsolete. -->
<NoWarn>$(NoWarn);SYSLIB0005;SYSLIB0037</NoWarn>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(CommonTestPath)System\IO\TempDirectory.cs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
<!-- LoadFrom_SameIdentityAsAssemblyWithDifferentPath_ReturnsEqualAssemblies test relies on no deps.json -->
<GenerateDependencyFile>false</GenerateDependencyFile>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn),SYSLIB0013</NoWarn>
<!-- SYSLIB0013: Uri.EscapeUriString is obsolete
SYSLIB0037: AssemblyName members HashAlgorithm, ProcessorArchitecture, and VersionCompatibility are obsolete. -->
<NoWarn>$(NoWarn);SYSLIB0013;SYSLIB0037</NoWarn>

<!-- these tests depend on the pdb files -->
<DebuggerSupport Condition="'$(DebuggerSupport)' == '' and '$(TargetOS)' == 'Browser'">true</DebuggerSupport>
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11363,12 +11363,15 @@ public AssemblyName(string assemblyName) { }
public string? EscapedCodeBase { get { throw null; } }
public System.Reflection.AssemblyNameFlags Flags { get { throw null; } set { } }
public string FullName { get { throw null; } }
[System.ObsoleteAttribute("AssemblyName members HashAlgorithm, ProcessorArchitecture, and VersionCompatibility are obsolete and not supported.", DiagnosticId = "SYSLIB0037", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public System.Configuration.Assemblies.AssemblyHashAlgorithm HashAlgorithm { get { throw null; } set { } }
[System.ObsoleteAttribute("Strong name signing is not supported and throws PlatformNotSupportedException.", DiagnosticId = "SYSLIB0017", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public System.Reflection.StrongNameKeyPair? KeyPair { get { throw null; } set { } }
public string? Name { get { throw null; } set { } }
[System.ObsoleteAttribute("AssemblyName members HashAlgorithm, ProcessorArchitecture, and VersionCompatibility are obsolete and not supported.", DiagnosticId = "SYSLIB0037", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public System.Reflection.ProcessorArchitecture ProcessorArchitecture { get { throw null; } set { } }
public System.Version? Version { get { throw null; } set { } }
[System.ObsoleteAttribute("AssemblyName members HashAlgorithm, ProcessorArchitecture, and VersionCompatibility are obsolete and not supported.", DiagnosticId = "SYSLIB0037", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public System.Configuration.Assemblies.AssemblyVersionCompatibility VersionCompatibility { get { throw null; } set { } }
public object Clone() { throw null; }
public static System.Reflection.AssemblyName GetAssemblyName(string assemblyFile) { throw null; }
Expand Down

0 comments on commit e10532a

Please sign in to comment.