Skip to content

Commit

Permalink
Mark LoadFrom overload that always throws as obsolete (#102292)
Browse files Browse the repository at this point in the history
Fixes #96410
  • Loading branch information
agocke committed May 17, 2024
1 parent 26bcc1d commit 12283e7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
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 @@ -177,5 +177,8 @@ internal static class Obsoletions

internal const string ArmIntrinsicPerformsUnsignedOperationMessage = "The underlying hardware instruction does not perform a signed saturate narrowing operation, and it always returns an unsigned result. Use the unsigned overload instead.";
internal const string ArmIntrinsicPerformsUnsignedOperationDiagId = "SYSLIB0055";

internal const string LoadFromHashAlgorithmMessage = "LoadFrom with a custom AssemblyHashAlgorithm is obsolete. Use overloads without an AssemblyHashAlgorithm.";
internal const string LoadFromHashAlgorithmDiagId = "SYSLIB0056";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ public static Assembly LoadFrom(string assemblyFile)
}

[RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")]
[Obsolete(Obsoletions.LoadFromHashAlgorithmMessage, DiagnosticId = Obsoletions.LoadFromHashAlgorithmDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public static Assembly LoadFrom(string assemblyFile, byte[]? hashValue, AssemblyHashAlgorithm hashAlgorithm)
{
throw new NotSupportedException(SR.NotSupported_AssemblyLoadFromHash);
Expand Down
1 change: 1 addition & 0 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11157,6 +11157,7 @@ public virtual void GetObjectData(System.Runtime.Serialization.SerializationInfo
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Types and members the loaded assembly depends on might be removed")]
public static System.Reflection.Assembly LoadFrom(string assemblyFile) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Types and members the loaded assembly depends on might be removed")]
[System.ObsoleteAttribute("LoadFrom with a custom AssemblyHashAlgorithm is obsolete. Use overloads without an AssemblyHashAlgorithm.", DiagnosticId = "SYSLIB0056", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public static System.Reflection.Assembly LoadFrom(string assemblyFile, byte[]? hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Types and members the loaded module depends on might be removed")]
public System.Reflection.Module LoadModule(string moduleName, byte[]? rawModule) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,20 @@ public void LoadFile_ValidPEBadIL_ThrowsBadImageFormatExceptionWithPath_ByInitia
AssertExtensions.ThrowsContains<BadImageFormatException>(() => Assembly.LoadFile(path), path);
}

#pragma warning disable SYSLIB0056 // AssemblyHashAlgorithm overload is not supported and throws NotSupportedException.
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void LoadFromUsingHashValue()
{
Assert.Throws<NotSupportedException>(() => Assembly.LoadFrom("abc", null, System.Configuration.Assemblies.AssemblyHashAlgorithm.SHA1));
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void LoadFrom_WithHashValue_ThrowsNotSupportedException()
{
Assert.Throws<NotSupportedException>(() => Assembly.LoadFrom(DestTestAssemblyPath, new byte[0], Configuration.Assemblies.AssemblyHashAlgorithm.None));
}
#pragma warning restore SYSLIB0056 // AssemblyHashAlgorithm overload is not supported and throws NotSupportedException.

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void LoadFrom_SamePath_ReturnsEqualAssemblies()
{
Expand Down Expand Up @@ -496,12 +504,6 @@ public void UnsafeLoadFrom_SamePath_ReturnsEqualAssemblies()
Assert.Equal(assembly1, assembly2);
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void LoadFrom_WithHashValue_ThrowsNotSupportedException()
{
Assert.Throws<NotSupportedException>(() => Assembly.LoadFrom(DestTestAssemblyPath, new byte[0], Configuration.Assemblies.AssemblyHashAlgorithm.None));
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void LoadModule()
{
Expand Down

0 comments on commit 12283e7

Please sign in to comment.