Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/project/list-of-diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ The PR that reveals the implementation of the `<IncludeInternalObsoleteAttribute
| __`SYSLIB0021`__ | Derived cryptographic types are obsolete. Use the Create method on the base type instead. |
| __`SYSLIB0022`__ | The Rijndael and RijndaelManaged types are obsolete. Use Aes instead. |
| __`SYSLIB0023`__ | RNGCryptoServiceProvider is obsolete. To generate a random number, use one of the RandomNumberGenerator static methods instead. |
| __`SYSLIB0024`__ | Creating and unloading AppDomains is not supported and throws an exception. |

## Analyzer Warnings

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 @@ -80,5 +80,8 @@ internal static class Obsoletions

internal const string RNGCryptoServiceProviderMessage = "RNGCryptoServiceProvider is obsolete. To generate a random number, use one of the RandomNumberGenerator static methods instead.";
internal const string RNGCryptoServiceProviderDiagId = "SYSLIB0023";

internal const string AppDomainCreateUnloadMessage = "Creating and unloading AppDomains is not supported and throws an exception.";
internal const string AppDomainCreateUnloadDiagId = "SYSLIB0024";
}
}
3 changes: 3 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/AppDomain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public string ApplyPolicy(string assemblyName)
return assemblyName;
}

[Obsolete(Obsoletions.AppDomainCreateUnloadMessage, DiagnosticId = Obsoletions.AppDomainCreateUnloadDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public static AppDomain CreateDomain(string friendlyName)
{
if (friendlyName == null) throw new ArgumentNullException(nameof(friendlyName));
Expand All @@ -114,6 +115,7 @@ public int ExecuteAssembly(string assemblyFile, string?[]? args)
}

[RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")]
[Obsolete(Obsoletions.CodeAccessSecurityMessage, DiagnosticId = Obsoletions.CodeAccessSecurityDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public int ExecuteAssembly(string assemblyFile, string?[]? args, byte[]? hashValue, Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_CAS); // This api is only meaningful for very specific partial trust/CAS scenarios
Expand Down Expand Up @@ -162,6 +164,7 @@ public int ExecuteAssemblyByName(string assemblyName, params string?[]? args) =>
public override string ToString() =>
SR.AppDomain_Name + FriendlyName + Environment.NewLineConst + SR.AppDomain_NoContextPolicies;

[Obsolete(Obsoletions.AppDomainCreateUnloadMessage, DiagnosticId = Obsoletions.AppDomainCreateUnloadDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public static void Unload(AppDomain domain)
{
if (domain == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ static void Write(string source, ref Span<char> dest)
}
}

[Obsolete(Obsoletions.BinaryFormatterMessage, DiagnosticId = Obsoletions.BinaryFormatterDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
protected event EventHandler<SafeSerializationEventArgs>? SerializeObjectState
{
add { throw new PlatformNotSupportedException(SR.PlatformNotSupported_SecureBinarySerialization); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,14 @@ public void ApplyPolicy()
Assert.Equal(AppDomain.CurrentDomain.ApplyPolicy(entryAssembly), entryAssembly);
}

#pragma warning disable SYSLIB0024 // Creating and unloading AppDomains is not supported and throws an exception.
[Fact]
public void CreateDomainNonNetfx()
{
AssertExtensions.Throws<ArgumentNullException>("friendlyName", () => { AppDomain.CreateDomain(null); });
Assert.Throws<PlatformNotSupportedException>(() => { AppDomain.CreateDomain("test"); });
}
#pragma warning restore SYSLIB0024

[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
public void ExecuteAssemblyByName()
Expand All @@ -269,8 +271,10 @@ public void ExecuteAssembly()
AssertExtensions.Throws<ArgumentNullException>("assemblyFile", () => AppDomain.CurrentDomain.ExecuteAssembly(null));
Assert.Throws<FileNotFoundException>(() => AppDomain.CurrentDomain.ExecuteAssembly("NonExistentFile.exe"));

#pragma warning disable SYSLIB0003 // Code Access Security is not supported or honored by the runtime.
Func<int> executeAssembly = () => AppDomain.CurrentDomain.ExecuteAssembly(name, new string[2] { "2", "3" }, null, Configuration.Assemblies.AssemblyHashAlgorithm.SHA1);
Assert.Throws<PlatformNotSupportedException>(() => executeAssembly());
#pragma warning restore SYSLIB0003

Assert.Equal(5, AppDomain.CurrentDomain.ExecuteAssembly(name));
Assert.Equal(10, AppDomain.CurrentDomain.ExecuteAssembly(name, new string[2] { "2", "3" }));
Expand Down Expand Up @@ -342,6 +346,7 @@ public void toString()
}).Dispose();
}

#pragma warning disable SYSLIB0024 // Creating and unloading AppDomains is not supported and throws an exception.
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
public void Unload()
{
Expand All @@ -350,6 +355,7 @@ public void Unload()
Assert.Throws<CannotUnloadAppDomainException>(() => { AppDomain.Unload(AppDomain.CurrentDomain); });
}).Dispose();
}
#pragma warning restore SYSLIB0024

[Fact]
public void Load()
Expand Down
4 changes: 4 additions & 0 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public void AppendPrivatePath(string? path) { }
public void ClearPrivatePath() { }
[System.ObsoleteAttribute("AppDomain.ClearShadowCopyPath has been deprecated. Please investigate the use of AppDomainSetup.ShadowCopyDirectories instead. https://go.microsoft.com/fwlink/?linkid=14202")]
public void ClearShadowCopyPath() { }
[System.ObsoleteAttribute("Creating and unloading AppDomains is not supported and throws an exception.", DiagnosticId = "SYSLIB0024", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public static System.AppDomain CreateDomain(string friendlyName) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Type and its constructor could be removed")]
public System.Runtime.Remoting.ObjectHandle? CreateInstance(string assemblyName, string typeName) { throw null; }
Expand Down Expand Up @@ -177,6 +178,7 @@ public void ClearShadowCopyPath() { }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Types and members the loaded assembly depends on might be removed")]
public int ExecuteAssembly(string assemblyFile, string?[]? args) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Types and members the loaded assembly depends on might be removed")]
[System.ObsoleteAttribute("Code Access Security is not supported or honored by the runtime.", DiagnosticId = "SYSLIB0003", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public int ExecuteAssembly(string assemblyFile, string?[]? args, byte[]? hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm) { throw null; }
public int ExecuteAssemblyByName(System.Reflection.AssemblyName assemblyName, params string?[]? args) { throw null; }
public int ExecuteAssemblyByName(string assemblyName) { throw null; }
Expand Down Expand Up @@ -207,6 +209,7 @@ public void SetShadowCopyFiles() { }
public void SetShadowCopyPath(string? path) { }
public void SetThreadPrincipal(System.Security.Principal.IPrincipal principal) { }
public override string ToString() { throw null; }
[System.ObsoleteAttribute("Creating and unloading AppDomains is not supported and throws an exception.", DiagnosticId = "SYSLIB0024", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public static void Unload(System.AppDomain domain) { }
}
public sealed partial class AppDomainSetup
Expand Down Expand Up @@ -2069,6 +2072,7 @@ public Exception(string? message, System.Exception? innerException) { }
public virtual string? Source { get { throw null; } set { } }
public virtual string? StackTrace { get { throw null; } }
public System.Reflection.MethodBase? TargetSite { get { throw null; } }
[System.ObsoleteAttribute("BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId = "SYSLIB0011", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
protected event System.EventHandler<System.Runtime.Serialization.SafeSerializationEventArgs>? SerializeObjectState { add { } remove { } }
public virtual System.Exception GetBaseException() { throw null; }
public virtual void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/System.Runtime/tests/System/ExceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,15 @@ public override string ToString()
return "DerivedException.ToString()";
}

#pragma warning disable SYSLIB0011 // BinaryFormatter serialization is obsolete and should not be used.
[Fact]
public static void Exception_SerializeObjectState()
{
var excp = new DerivedException();
Assert.Throws<PlatformNotSupportedException>(() => excp.SerializeObjectState += (exception, eventArgs) => eventArgs.AddSerializedState(null));
Assert.Throws<PlatformNotSupportedException>(() => excp.SerializeObjectState -= (exception, eventArgs) => eventArgs.AddSerializedState(null));
}
#pragma warning restore SYSLIB0011

[Fact]
public static void Exception_OverriddenToStringOnInnerException()
Expand Down