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
Original file line number Diff line number Diff line change
Expand Up @@ -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();
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 @@ -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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,15 @@ 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")]
get => _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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/libraries/System.Reflection/tests/AssemblyNameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; } }
Expand Down