Skip to content

Mark Assembly.CodeBase as obsolete #31127

Closed

Description

@terrajobst

Assembly.Location and Assembly.CodeBase are very similar, but not the same thing. To reduce confusion, we should mark it as obsolete.

Reason

Having two things that are similar, but not identical always causes confusion. Here is an example.

As @jkotas said:

Assembly.Location is strictly better than Assembly.CodeBase.

Assembly.CodeBase is an obsolete property. The only reason why it was included in .NET Core was .NET Framework compatibility. The original purpose of Assembly.CodeBase was CAS (Code Access Security). It was meant to describe where the assembly was downloaded from for the Internet Zone security checks. It also explains some of its weird behaviors. For example, if the assembly is loaded as byte array, it returns the location of the caller of the Assembly.Load method.

Proposed API

namespace System.Reflection
{
    public partial class Assembly
    {
        [Obsolete("Use Location instead.")]
        public virtual string CodeBase { get; }
    }
}

Activity

  1. terrajobst commented on Oct 22, 2019

    @terrajobst
    ContributorAuthor

    Video

    Looks good. We should also mark it as [EditorBrowsable(Never)].

    namespace System.Reflection
    {
        public partial class Assembly
        {
            [Obsolete("Use Location instead.")]
            public virtual string CodeBase { get; }
        }
    }
  2. vitek-karas commented on Oct 27, 2019

    @vitek-karas
    Member

    Should we also consider obsoleting AssemblyName.CodeBase? It's not exactly the same thing, but quite related - in fact that property has no functional effect (trying to load assembly via AssemblyName will ignore the CodeBase property anyway: https://github.com/dotnet/coreclr/blob/master/src/System.Private.CoreLib/src/System/Reflection/Assembly.CoreCLR.cs#L63

  3. jkotas commented on Jan 30, 2020

    @jkotas
    Member

    Assembly.EscapedCodeBase should be marked as obsolete as well.

  4. bitbonk commented on Jan 30, 2020

    @bitbonk
    Contributor

    Just out of curiosity: Since those APIs are part of .NET Standard, what implications does marking APIs as obsolete have for .NET Standard?

    Since in .NET Standard, APIs cannot be removed, only added, does that mean you will only obsolete those APs but never remove them? Or will .NET Standard itself become obsolete due to the unification in .NET 5.

  5. jkotas commented on Jan 30, 2020

    @jkotas
    Member

    Right, we do not have plans to remove any netstandard APIs.

  6. transferred this issue fromdotnet/corefxon Feb 1, 2020
  7. added this to the 5.0 milestone on Feb 1, 2020
  8. added
    untriaged
    on Feb 23, 2020
  9. removed
    untriaged
    on Mar 3, 2020
  10. added
    good first issue
    help wanted
    on Jul 7, 2020
  11. JoshSchreuder commented on Jul 14, 2020

    @JoshSchreuder
    Contributor

    I started looking at this, but need a little clarification as I'm unfamiliar with the code structure.

    With my change, I'm getting the following errors where CodeBase / EscapedCodeBase are used elsewhere (DesigntimeLicenseContext, Helper.Win32Unix, RoAssembly). Can I please get some tips on the best way to resolve these?

    System\ComponentModel\Design\DesigntimeLicenseContext.cs(88,56): error CS0618: 'Assembly.EscapedCodeBase' is obsolete: 'EscapedCodeBase is only included for .NET Framework compatibility. Use Location instead.' [C:\Work\dotnetruntime\src\libraries\System.ComponentModel.TypeConverter\src\System.ComponentModel.TypeConverter.csproj]
    System\ComponentModel\Design\DesigntimeLicenseContext.cs(111,45): error CS0618: 'Assembly.EscapedCodeBase' is obsolete: 'EscapedCodeBase is only included for .NET Framework compatibility. Use Location instead.' [C:\Work\dotnetruntime\src\libraries\System.ComponentModel.TypeConverter\src\System.ComponentModel.TypeConverter.csproj]
    System\IO\IsolatedStorage\Helper.Win32Unix.cs(57,36): error CS0618: 'Assembly.CodeBase' is obsolete: 'CodeBase is only included for .NET Framework compatibility. Use Location instead.' [C:\Work\dotnetruntime\src\libraries\System.IO.IsolatedStorage\src\System.IO.IsolatedStorage.csproj]
    System\Reflection\TypeLoading\Assemblies\RoAssembly.cs(44,39): error CS0672: Member 'RoAssembly.CodeBase' overrides obsolete member 'Assembly.CodeBase'. Add the Obsolete attribute to 'RoAssembly.CodeBase'. [C:\Work\dotnetruntime\src\libraries\System.Reflection.MetadataLoadContext\src\System.Reflection.MetadataLoadContext.csproj]
    System\Reflection\TypeLoading\Assemblies\RoAssembly.cs(45,39): error CS0672: Member 'RoAssembly.EscapedCodeBase' overrides obsolete member 'Assembly.EscapedCodeBase'. Add the Obsolete attribute to 'RoAssembly.EscapedCodeBase'. [C:\Work\dotnetruntime\src\libraries\System.Reflection.MetadataLoadContext\src\System.Reflection.MetadataLoadContext.csproj]
    

    Additionally, does this need something done per Better Obsoletions? How would I go about getting an aka.ms to put into list-of-obsoletions.md?

  12. jkotas commented on Jul 14, 2020

    @jkotas
    Member

    System.ComponentModel.TypeConverter should be switched to use Assembly.Location. The rest should use #pragmas to disable the warnings.

    does this need something done per Better Obsoletions?

    @jeffhandley is working on the plan for better obsoletions IDs. You can leave the ID as TODO in the PR.

  13. 4 remaining items

  14. jkotas commented on Jul 17, 2020

    @jkotas
    Member

    We should also mark it as [EditorBrowsable(Never)]

    @terrajobst Is marking it as [EditorBrowsable(Never)] still valid with the new obsoletion plan? We are marking a lot of other methods obsolete, but we are not marking them as [EditorBrowsable(Never)]. What is special about this method that it deserves to be marked with [EditorBrowsable(Never)]?

    cc @jeffhandley

  15. jeffhandley commented on Jul 17, 2020

    @jeffhandley
    Member

    Per the non-goals of the better obsoletion spec, it is not expected that we'll mark [EditorBrowsable(Never)] in conjunction with the obsoletion but that they should be independent decisions. I took the approach to not apply the EditorBrowsable attribute in the big obsoletion PR.

    I recommend we remove the EditorBrowable attributes from the obsoletions here too.

  16. JoshSchreuder commented on Jul 19, 2020

    @JoshSchreuder
    Contributor

    Updated PR with the new Obsoletion stuff, and removed the EditorBrowsable attribute, thanks all!

  17. vitek-karas commented on Jul 30, 2020

    @vitek-karas
    Member

    Should we also look into AssemblyName.CodeBase and AssemblyName.EscapedCodeBase - they are very similar to Assembly.CodeBase:

    • Runtime fills in the same values for loaded assemblies
    • When constructed manually the value is preserved
    • Runtime never actually consumes these values - calling Assembly.Load(AssemblyName) completely ignores these properties on the name.
  18. danmoseley commented on Aug 18, 2020

    @danmoseley
    Contributor

    Was there an answer to this question?

    Should we also look into AssemblyName.CodeBase and AssemblyName.EscapedCodeBase - they are very similar to Assembly.CodeBase:

  19. terrajobst commented on Aug 18, 2020

    @terrajobst
    ContributorAuthor

    Yes, @jkotas mentioned it above:

    Assembly.EscapedCodeBase should be marked as obsolete as well.

    And the PR marked it.

  20. vitek-karas commented on Aug 18, 2020

    @vitek-karas
    Member

    What about the AssemblyName variants - they return basically the exact same thing... and AFAIK are not marked right now.

  21. ghost locked as resolved and limited conversation to collaborators on Dec 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedarea-System.Reflectiongood first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions