Skip to content

Commit 12283e7

Browse files
authored
Mark LoadFrom overload that always throws as obsolete (#102292)
Fixes #96410
1 parent 26bcc1d commit 12283e7

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

src/libraries/Common/src/System/Obsoletions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,8 @@ internal static class Obsoletions
177177

178178
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.";
179179
internal const string ArmIntrinsicPerformsUnsignedOperationDiagId = "SYSLIB0055";
180+
181+
internal const string LoadFromHashAlgorithmMessage = "LoadFrom with a custom AssemblyHashAlgorithm is obsolete. Use overloads without an AssemblyHashAlgorithm.";
182+
internal const string LoadFromHashAlgorithmDiagId = "SYSLIB0056";
180183
}
181184
}

src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ public static Assembly LoadFrom(string assemblyFile)
385385
}
386386

387387
[RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")]
388+
[Obsolete(Obsoletions.LoadFromHashAlgorithmMessage, DiagnosticId = Obsoletions.LoadFromHashAlgorithmDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
388389
public static Assembly LoadFrom(string assemblyFile, byte[]? hashValue, AssemblyHashAlgorithm hashAlgorithm)
389390
{
390391
throw new NotSupportedException(SR.NotSupported_AssemblyLoadFromHash);

src/libraries/System.Runtime/ref/System.Runtime.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11157,6 +11157,7 @@ public virtual void GetObjectData(System.Runtime.Serialization.SerializationInfo
1115711157
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Types and members the loaded assembly depends on might be removed")]
1115811158
public static System.Reflection.Assembly LoadFrom(string assemblyFile) { throw null; }
1115911159
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Types and members the loaded assembly depends on might be removed")]
11160+
[System.ObsoleteAttribute("LoadFrom with a custom AssemblyHashAlgorithm is obsolete. Use overloads without an AssemblyHashAlgorithm.", DiagnosticId = "SYSLIB0056", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
1116011161
public static System.Reflection.Assembly LoadFrom(string assemblyFile, byte[]? hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm) { throw null; }
1116111162
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Types and members the loaded module depends on might be removed")]
1116211163
public System.Reflection.Module LoadModule(string moduleName, byte[]? rawModule) { throw null; }

src/libraries/System.Runtime/tests/System.Reflection.Tests/AssemblyTests.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,12 +442,20 @@ public void LoadFile_ValidPEBadIL_ThrowsBadImageFormatExceptionWithPath_ByInitia
442442
AssertExtensions.ThrowsContains<BadImageFormatException>(() => Assembly.LoadFile(path), path);
443443
}
444444

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

452+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
453+
public void LoadFrom_WithHashValue_ThrowsNotSupportedException()
454+
{
455+
Assert.Throws<NotSupportedException>(() => Assembly.LoadFrom(DestTestAssemblyPath, new byte[0], Configuration.Assemblies.AssemblyHashAlgorithm.None));
456+
}
457+
#pragma warning restore SYSLIB0056 // AssemblyHashAlgorithm overload is not supported and throws NotSupportedException.
458+
451459
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
452460
public void LoadFrom_SamePath_ReturnsEqualAssemblies()
453461
{
@@ -496,12 +504,6 @@ public void UnsafeLoadFrom_SamePath_ReturnsEqualAssemblies()
496504
Assert.Equal(assembly1, assembly2);
497505
}
498506

499-
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
500-
public void LoadFrom_WithHashValue_ThrowsNotSupportedException()
501-
{
502-
Assert.Throws<NotSupportedException>(() => Assembly.LoadFrom(DestTestAssemblyPath, new byte[0], Configuration.Assemblies.AssemblyHashAlgorithm.None));
503-
}
504-
505507
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
506508
public void LoadModule()
507509
{

0 commit comments

Comments
 (0)