Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotate unsupported APIs in .Net core as Obsolete - Reflection area #50941

Merged
merged 11 commits into from
Apr 25, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,13 @@ public static Assembly LoadFrom(string assemblyFile, byte[]? hashValue, Assembly
[RequiresUnreferencedCode("Types and members the loaded module depends on might be removed")]
public virtual Module LoadModule(string moduleName, byte[]? rawModule, byte[]? rawSymbolStore) { throw NotImplemented.ByDesign; }

[Obsolete("ReflectionOnly loading is not supported on this platform.")]
[RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")]
public static Assembly ReflectionOnlyLoad(byte[] rawAssembly) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); }
[Obsolete("ReflectionOnly loading is not supported on this platform.")]
[RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")]
public static Assembly ReflectionOnlyLoad(string assemblyString) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); }
[Obsolete("ReflectionOnly loading is not supported on this platform.")]
[RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")]
public static Assembly ReflectionOnlyLoadFrom(string assemblyFile) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ public StrongNameKeyPair(byte[] keyPairArray)
protected StrongNameKeyPair(SerializationInfo info, StreamingContext context) =>
throw new PlatformNotSupportedException();

[Obsolete("Strong-name signing is not supported on this platform.")]
public StrongNameKeyPair(string keyPairContainer) =>
throw new PlatformNotSupportedException(SR.PlatformNotSupported_StrongNameSigning);

[Obsolete("Strong-name signing is not supported on this platform.")]
public byte[] PublicKey =>
throw new PlatformNotSupportedException(SR.PlatformNotSupported_StrongNameSigning);

Expand Down
1 change: 1 addition & 0 deletions src/libraries/System.Private.CoreLib/src/System/Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ public override int GetHashCode()
}
public virtual bool Equals(Type? o) => o == null ? false : object.ReferenceEquals(this.UnderlyingSystemType, o.UnderlyingSystemType);

[Obsolete("ReflectionOnly loading is not supported on this platform.")]
public static Type? ReflectionOnlyGetType(string typeName, bool throwIfNotFound, bool ignoreCase) => throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly);

public static Binder DefaultBinder
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/System.Reflection/tests/AssemblyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ public void AssemblyLoadFromBytesWithSymbols()
Assert.Equal(assembly.FullName, loadedAssembly.FullName);
}

#pragma warning disable CS0618 // ReflectionOnly loading is not supported on this platform.
[Fact]
public void AssemblyReflectionOnlyLoadFromString()
{
Expand All @@ -750,6 +751,7 @@ public void AssemblyReflectionOnlyLoadFromNeg()
Assert.Throws<PlatformNotSupportedException>(() => Assembly.ReflectionOnlyLoad(string.Empty));
Assert.Throws<PlatformNotSupportedException>(() => Assembly.ReflectionOnlyLoad((byte[])null));
}
#pragma warning restore CS0618

public static IEnumerable<object[]> GetModules_TestData()
{
Expand Down
6 changes: 6 additions & 0 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4427,6 +4427,7 @@ protected Type() { }
public virtual System.Type MakePointerType() { throw null; }
public static bool operator ==(System.Type? left, System.Type? right) { throw null; }
public static bool operator !=(System.Type? left, System.Type? right) { throw null; }
[System.ObsoleteAttribute("ReflectionOnly loading is not supported on this platform.")]
public static System.Type? ReflectionOnlyGetType(string typeName, bool throwIfNotFound, bool ignoreCase) { throw null; }
public override string ToString() { throw null; }
}
Expand Down Expand Up @@ -7798,10 +7799,13 @@ public virtual void GetObjectData(System.Runtime.Serialization.SerializationInfo
public static System.Reflection.Assembly? LoadWithPartialName(string partialName) { throw null; }
public static bool operator ==(System.Reflection.Assembly? left, System.Reflection.Assembly? right) { throw null; }
public static bool operator !=(System.Reflection.Assembly? left, System.Reflection.Assembly? right) { throw null; }
[System.ObsoleteAttribute("ReflectionOnly loading is not supported on this platform.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Types and members the loaded assembly depends on might be removed")]
public static System.Reflection.Assembly ReflectionOnlyLoad(byte[] rawAssembly) { throw null; }
[System.ObsoleteAttribute("ReflectionOnly loading is not supported on this platform.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Types and members the loaded assembly depends on might be removed")]
public static System.Reflection.Assembly ReflectionOnlyLoad(string assemblyString) { throw null; }
[System.ObsoleteAttribute("ReflectionOnly loading is not supported on this platform.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Types and members the loaded assembly depends on might be removed")]
public static System.Reflection.Assembly ReflectionOnlyLoadFrom(string assemblyFile) { throw null; }
public override string ToString() { throw null; }
Expand Down Expand Up @@ -8773,7 +8777,9 @@ public partial class StrongNameKeyPair : System.Runtime.Serialization.IDeseriali
public StrongNameKeyPair(byte[] keyPairArray) { }
public StrongNameKeyPair(System.IO.FileStream keyPairFile) { }
protected StrongNameKeyPair(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
[System.ObsoleteAttribute("Strong-name signing is not supported on this platform.")]
public StrongNameKeyPair(string keyPairContainer) { }
[System.ObsoleteAttribute("Strong-name signing is not supported on this platform.")]
public byte[] PublicKey { get { throw null; } }
void System.Runtime.Serialization.IDeserializationCallback.OnDeserialization(object? sender) { }
void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void Ctor_NullKeyPairFile_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>("keyPairFile", () => new StrongNameKeyPair((FileStream)null));
}

#pragma warning disable CS0618 // Strong-name signing is not supported on this platform.
[Theory]
[InlineData(null)]
[InlineData("")]
Expand All @@ -72,7 +72,7 @@ public void PublicKey_Get_ThrowsPlatformNotSupportedException()
var keyPair = new StrongNameKeyPair(new byte[0]);
Assert.Throws<PlatformNotSupportedException>(() => keyPair.PublicKey);
}

#pragma warning restore CS0618
[Fact]
public void GetObjectData_Invoke_ThrowsPlatformNotSupportedException()
{
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/System.Runtime/tests/System/Type/TypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,11 @@ public void GetTypeCode_ValidType_ReturnsExpected(Type t, TypeCode typeCode)
[Fact]
public void ReflectionOnlyGetType()
{
#pragma warning disable CS0618 // ReflectionOnly loading is not supported on this platform.
Assert.Throws<PlatformNotSupportedException>(() => Type.ReflectionOnlyGetType(null, true, false));
Assert.Throws<PlatformNotSupportedException>(() => Type.ReflectionOnlyGetType("", true, true));
Assert.Throws<PlatformNotSupportedException>(() => Type.ReflectionOnlyGetType("System.Tests.TypeTests", false, true));
#pragma warning restore CS0618
}

[Fact]
Expand Down