diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs index c6c20002f2cdcb..fa602e0c1dc390 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs @@ -134,9 +134,10 @@ public override AssemblyName GetName(bool copiedName) an.RawFlags = GetFlags() | AssemblyNameFlags.PublicKey; -#pragma warning disable IL3000 // System.Reflection.AssemblyName.CodeBase' always returns an empty string for assemblies embedded in a single-file app. +#pragma warning disable IL3000, SYSLIB0044 // System.Reflection.AssemblyName.CodeBase' always returns an empty string for assemblies embedded in a single-file app. + // AssemblyName.CodeBase and AssemblyName.EscapedCodeBase are obsolete. Using them for loading an assembly is not supported. an.CodeBase = GetCodeBase(); -#pragma warning restore IL3000 +#pragma warning restore IL3000, SYSLIB0044 #pragma warning disable SYSLIB0037 // AssemblyName.HashAlgorithm is obsolete an.HashAlgorithm = GetHashAlgorithm(); diff --git a/src/libraries/Common/src/System/Obsoletions.cs b/src/libraries/Common/src/System/Obsoletions.cs index 0e96926467077c..bf9e6a0b990b90 100644 --- a/src/libraries/Common/src/System/Obsoletions.cs +++ b/src/libraries/Common/src/System/Obsoletions.cs @@ -141,5 +141,8 @@ internal static class Obsoletions internal const string EcDhPublicKeyBlobMessage = "ECDiffieHellmanPublicKey.ToByteArray() and the associated constructor do not have a consistent and interoperable implementation on all platforms. Use ECDiffieHellmanPublicKey.ExportSubjectPublicKeyInfo() instead."; internal const string EcDhPublicKeyBlobDiagId = "SYSLIB0043"; + + internal const string AssemblyNameCodeBaseMessage = "AssemblyName.CodeBase and AssemblyName.EscapedCodeBase are obsolete. Using them for loading an assembly is not supported."; + internal const string AssemblyNameCodeBaseDiagId = "SYSLIB0044"; } } diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AssemblyCatalog.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AssemblyCatalog.cs index d35b5df575d1f5..3eeb586b5f910b 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AssemblyCatalog.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AssemblyCatalog.cs @@ -558,7 +558,9 @@ private static Assembly LoadAssembly(string codeBase) catch (ArgumentException) { assemblyName = new AssemblyName(); +#pragma warning disable SYSLIB0044 // AssemblyName.CodeBase and AssemblyName.EscapedCodeBase are obsolete. Using them for loading an assembly is not supported. assemblyName.CodeBase = codeBase; +#pragma warning restore SYSLIB0044 } try diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs index b5034994b45134..479c6199feceb2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs @@ -82,6 +82,7 @@ public string? CultureName set => _cultureInfo = (value == null) ? null : new CultureInfo(value); } + [Obsolete(Obsoletions.AssemblyNameCodeBaseMessage, DiagnosticId = Obsoletions.AssemblyNameCodeBaseDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public string? CodeBase { [RequiresAssemblyFiles("The code will return an empty string for assemblies embedded in a single-file app")] @@ -89,6 +90,7 @@ public string? CodeBase set => _codeBase = value; } + [Obsolete(Obsoletions.AssemblyNameCodeBaseMessage, DiagnosticId = Obsoletions.AssemblyNameCodeBaseDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] [RequiresAssemblyFiles("The code will return an empty string for assemblies embedded in a single-file app")] public string? EscapedCodeBase { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compilation.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compilation.cs index eb198919446b98..bb49980d6b115c 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compilation.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compilation.cs @@ -162,7 +162,6 @@ internal void InitAssemblyMethods(XmlMapping[] xmlMappings) serializerName = Compiler.GetTempAssemblyName(name, defaultNamespace); // use strong name name.Name = serializerName; - name.CodeBase = null; name.CultureInfo = CultureInfo.InvariantCulture; try diff --git a/src/libraries/System.Reflection/tests/AssemblyNameTests.cs b/src/libraries/System.Reflection/tests/AssemblyNameTests.cs index 612ca620ee7a01..ce1f29b4789549 100644 --- a/src/libraries/System.Reflection/tests/AssemblyNameTests.cs +++ b/src/libraries/System.Reflection/tests/AssemblyNameTests.cs @@ -235,7 +235,7 @@ public void Verify_CultureName() AssemblyName an = new AssemblyName("MyAssemblyName"); Assert.Null(an.CultureName); } - +#pragma warning disable SYSLIB0044 // AssemblyName.CodeBase .AssemblyName.EscapedCodeBase are obsolete [Fact] public void Verify_CodeBase() { @@ -259,6 +259,7 @@ public static void Verify_EscapedCodeBase() n.CodeBase = @"file:///c:/program files/MyAssemblyName.dll"; Assert.Equal(n.EscapedCodeBase, Uri.EscapeUriString(n.CodeBase)); } +#pragma warning restore SYSLIB0044 [Fact] public static void Verify_HashAlgorithm() diff --git a/src/libraries/System.Runtime.Extensions/tests/System/AppDomainTests.cs b/src/libraries/System.Runtime.Extensions/tests/System/AppDomainTests.cs index 9aa3789453b6a4..24f763de070595 100644 --- a/src/libraries/System.Runtime.Extensions/tests/System/AppDomainTests.cs +++ b/src/libraries/System.Runtime.Extensions/tests/System/AppDomainTests.cs @@ -254,7 +254,6 @@ public void ExecuteAssemblyByName() Assert.Equal(10, AppDomain.CurrentDomain.ExecuteAssemblyByName(assembly.FullName, new string[2] { "2", "3" })); Assert.Throws(() => AppDomain.CurrentDomain.ExecuteAssemblyByName(assembly.FullName, new string[1] { "a" })); AssemblyName assemblyName = assembly.GetName(); - assemblyName.CodeBase = null; Assert.Equal(105, AppDomain.CurrentDomain.ExecuteAssemblyByName(assemblyName, new string[3] { "50", "25", "25" })); }).Dispose(); } @@ -358,7 +357,6 @@ public void Unload() public void Load() { AssemblyName assemblyName = typeof(AppDomainTests).Assembly.GetName(); - assemblyName.CodeBase = null; Assert.NotNull(AppDomain.CurrentDomain.Load(assemblyName)); Assert.NotNull(AppDomain.CurrentDomain.Load(typeof(AppDomainTests).Assembly.FullName)); } diff --git a/src/libraries/System.Runtime.Loader/tests/AssemblyLoadContextTest.cs b/src/libraries/System.Runtime.Loader/tests/AssemblyLoadContextTest.cs index 82097bf4a6f21d..43f3a0726de3be 100644 --- a/src/libraries/System.Runtime.Loader/tests/AssemblyLoadContextTest.cs +++ b/src/libraries/System.Runtime.Loader/tests/AssemblyLoadContextTest.cs @@ -115,7 +115,6 @@ public static void LoadFromAssemblyName_AssemblyNotFound() public static void LoadFromAssemblyName_ValidTrustedPlatformAssembly() { var asmName = typeof(System.Linq.Enumerable).Assembly.GetName(); - asmName.CodeBase = null; var loadContext = new CustomTPALoadContext(); // We should be able to override (and thus, load) assemblies that were @@ -131,7 +130,6 @@ public static void LoadFromAssemblyName_ValidTrustedPlatformAssembly() public static void LoadFromAssemblyName_FallbackToDefaultContext() { var asmName = typeof(System.Linq.Enumerable).Assembly.GetName(); - asmName.CodeBase = null; var loadContext = new AssemblyLoadContext("FallbackToDefaultContextTest"); // This should not have any special handlers, so it should just find the version in the default context diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index a9a6194f326dff..2e094c0358b1a7 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -10828,11 +10828,13 @@ public sealed partial class AssemblyName : System.ICloneable, System.Runtime.Ser { public AssemblyName() { } public AssemblyName(string assemblyName) { } + [System.ObsoleteAttribute("AssemblyName.CodeBase and AssemblyName.EscapedCodeBase are obsolete. Using them for loading an assembly is not supported.", DiagnosticId = "SYSLIB0044", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] public string? CodeBase { [System.Diagnostics.CodeAnalysis.RequiresAssemblyFilesAttribute("The code will return an empty string for assemblies embedded in a single-file app")] get { throw null; } set { } } public System.Reflection.AssemblyContentType ContentType { get { throw null; } set { } } public System.Globalization.CultureInfo? CultureInfo { get { throw null; } set { } } public string? CultureName { get { throw null; } set { } } [System.Diagnostics.CodeAnalysis.RequiresAssemblyFilesAttribute("The code will return an empty string for assemblies embedded in a single-file app")] + [System.ObsoleteAttribute("AssemblyName.CodeBase and AssemblyName.EscapedCodeBase are obsolete. Using them for loading an assembly is not supported.", DiagnosticId = "SYSLIB0044", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] public string? EscapedCodeBase { get { throw null; } } public System.Reflection.AssemblyNameFlags Flags { get { throw null; } set { } } public string FullName { get { throw null; } }