Skip to content

Commit

Permalink
Mark Assembly.CodeBase / Assembly.EscapedCodeBase as obsolete (dotnet…
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Schreuder committed Jul 26, 2020
1 parent 7b1b7b2 commit 552474f
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ public class TestAssemblyFour { }

public class AssemblyCatalogTestsHelper
{
#pragma warning disable 618
protected string GetAttributedAssemblyCodeBase()
{
return Assembly.GetExecutingAssembly().CodeBase;
}
#pragma warning restore 618

protected Assembly GetAttributedAssembly()
{
Expand Down Expand Up @@ -74,7 +76,9 @@ internal static void Constructor_ValueAsCodebaseArgument_ShouldSetAssemblyProper

foreach (var e in expectations)
{
#pragma warning disable 618
var catalog = catalogCreator(e.CodeBase);
#pragma warning restore 618

Assert.Same(e, catalog.Assembly);
}
Expand Down Expand Up @@ -694,6 +698,7 @@ public void Constructor8_NullReflectionContextArgument_ShouldThrowArgumentNull()
});
}

#pragma warning disable 618
[Fact]
public void Constructor8_NullDefinitionOriginArgument_ShouldThrowArgumentNull()
{
Expand All @@ -702,6 +707,7 @@ public void Constructor8_NullDefinitionOriginArgument_ShouldThrowArgumentNull()
return new AssemblyCatalog(GetAttributedAssembly().CodeBase, new AssemblyCatalogTestsReflectionContext(), dO);
});
}
#pragma warning restore 618

//=========================================================================================================================================
// Test cases for Assemblies decorated with the CatalogDiscoveryAttribute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ public override string GetSavedLicenseKey(Type type, Assembly resourceAssembly)
{
// Though, I could not repro this, we seem to be hitting an AssemblyBuilder
// when walking through all the assemblies in the current app domain. This throws an
// exception on Assembly.CodeBase and we bail out. Catching exceptions here is not a
// exception on Assembly.Location and we bail out. Catching exceptions here is not a
// bad thing.
if (asm.IsDynamic)
continue;

// file://fullpath/foo.exe
string fileName = GetLocalPath(asm.EscapedCodeBase);
string fileName = GetLocalPath(asm.Location);
fileName = new FileInfo(fileName).Name;

Stream s = asm.GetManifestResourceStream(fileName + ".licenses");
Expand All @@ -105,10 +105,10 @@ public override string GetSavedLicenseKey(Type type, Assembly resourceAssembly)
}
else if (!resourceAssembly.IsDynamic)
{
// EscapedCodeBase won't be supported by emitted assemblies anyway
// Location won't be supported by emitted assemblies anyway
string fileName;

fileName = GetLocalPath(resourceAssembly.EscapedCodeBase);
fileName = GetLocalPath(resourceAssembly.Location);

fileName = Path.GetFileName(fileName);
string licResourceName = fileName + ".licenses";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ internal static void GetDefaultIdentityAndHash(out object identity, out string h
throw new IsolatedStorageException(SR.IsolatedStorage_Init);

AssemblyName assemblyName = assembly.GetName();
#pragma warning disable 618
Uri codeBase = new Uri(assembly.CodeBase!);
#pragma warning restore 618

hash = IdentityHelper.GetNormalizedStrongNameHash(assemblyName)!;
if (hash != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace System.Reflection.Emit
public sealed partial class AssemblyBuilder : System.Reflection.Assembly
{
internal AssemblyBuilder() { }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("CodeBase is only included for .NET Framework compatibility. Use Location instead.", DiagnosticId = "TODO", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public override string? CodeBase { get { throw null; } }
public override System.Reflection.MethodInfo? EntryPoint { get { throw null; } }
public override string? FullName { get { throw null; } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ protected RoAssembly(MetadataLoadContext loader, int assemblyFileCount)

// Location and codebase
public abstract override string Location { get; }
#pragma warning disable 672
public sealed override string CodeBase => throw new NotSupportedException(SR.NotSupported_AssemblyCodeBase);
public sealed override string EscapedCodeBase => throw new NotSupportedException(SR.NotSupported_AssemblyCodeBase);
#pragma warning restore 672

// Custom Attributes
public sealed override IList<CustomAttributeData> GetCustomAttributesData() => CustomAttributes.ToReadOnlyCollection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ public static void TestRestrictions()
{
Assembly a = lc.LoadFromAssemblyPath(typeof(TopLevelType).Assembly.Location);

#pragma warning disable 618
Assert.Throws<NotSupportedException>(() => a.CodeBase);
Assert.Throws<NotSupportedException>(() => a.EscapedCodeBase);
#pragma warning restore 618
Assert.Throws<NotSupportedException>(() => a.GetObjectData(null, default));
Assert.Throws<NotSupportedException>(() => a.GetSatelliteAssembly(null));
Assert.Throws<NotSupportedException>(() => a.GetSatelliteAssembly(null, null));
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 @@ -464,11 +464,13 @@ public void Location_ExecutingAssembly_IsNotNull()
Assert.NotNull(Helpers.ExecutingAssembly.Location);
}

#pragma warning disable 618
[Fact]
public void CodeBase()
{
Assert.NotEmpty(Helpers.ExecutingAssembly.CodeBase);
}
#pragma warning restore 618

[Fact]
public void ImageRuntimeVersion()
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 @@ -7564,10 +7564,14 @@ public AmbiguousMatchException(string? message, System.Exception? inner) { }
public abstract partial class Assembly : System.Reflection.ICustomAttributeProvider, System.Runtime.Serialization.ISerializable
{
protected Assembly() { }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("CodeBase is only included for .NET Framework compatibility. Use Location instead.", DiagnosticId = "TODO", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public virtual string? CodeBase { get { throw null; } }
public virtual System.Collections.Generic.IEnumerable<System.Reflection.CustomAttributeData> CustomAttributes { get { throw null; } }
public virtual System.Collections.Generic.IEnumerable<System.Reflection.TypeInfo> DefinedTypes { [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Types might be removed")] get { throw null; } }
public virtual System.Reflection.MethodInfo? EntryPoint { get { throw null; } }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("EscapedCodeBase is only included for .NET Framework compatibility. Use Location instead.", DiagnosticId = "TODO", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public virtual string EscapedCodeBase { get { throw null; } }
public virtual System.Collections.Generic.IEnumerable<System.Type> ExportedTypes { [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Types might be removed")] get { throw null; } }
public virtual string? FullName { get { throw null; } }
Expand Down

0 comments on commit 552474f

Please sign in to comment.