未验证 提交 042fdf43 编写于 作者: B Buyaa Namnan 提交者: GitHub

Obsolete AssemblyName.CodeBase, AssemblyName.EscapedCodeBase (#70534)

上级 0ca092e8
......@@ -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();
......
......@@ -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";
}
}
......@@ -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
......
......@@ -82,6 +82,7 @@ public AssemblyName()
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 AssemblyName()
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
{
......
......@@ -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
......
......@@ -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()
......
......@@ -254,7 +254,6 @@ public void ExecuteAssemblyByName()
Assert.Equal(10, AppDomain.CurrentDomain.ExecuteAssemblyByName(assembly.FullName, new string[2] { "2", "3" }));
Assert.Throws<FormatException>(() => 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));
}
......
......@@ -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
......
......@@ -10781,11 +10781,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; } }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册