Skip to content

AssemblyName.CodeBase is ignored in LoadFromAssemblyName #59565

Closed

Description

@adrianm64

Description

When porting a .NET Framework application to core I replaced

...
assemblyName.CodeBase = "C:\Path\To\Assembly.dll";
var assembly = Assembly.Load(assemblyName);

with

...
assemblyName.CodeBase = "C:\Path\To\Assembly.dll";
var assembly = AssemblyLoadContext.Default.LoadFromAssemblyName(assemblyName);

But it didn't work. It ignored the path in CodeBase and used the normal assembly loading pattern.

I changed the code to

var assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath("C:\Path\To\Assembly.dll");

which works fine.

Expected behavior

LoadFromAssemblyName using CodeBase or a a compiler warning/error when assigning the AssemblyName.CodeBase property.

Configuration

Microsoft NetCoreApp 3.1.0

Regression?

Yes, worked in .NET Framework

Activity

  1. ghost added
    area-AssemblyLoader-coreclr
    on Sep 24, 2021
  2. ghost added
    untriaged
    on Sep 24, 2021
  3. vitek-karas commented on Sep 24, 2021

    @vitek-karas
    Member

    CodeBase is obsolete in .NET Core/.NET5 +. In fact Assembly.CodeBase is already marked as obsolete, but AssemblyName.CodeBase isn't (overlooked unfortunately).

    This is effectively a duplicate of #42857.

  4. adrianm64 commented on Sep 24, 2021

    @adrianm64
    Author

    Thank you for the quick response.

  5. ghost locked as resolved and limited conversation to collaborators on Nov 3, 2021
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

    area-AssemblyLoader-coreclruntriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions