Skip to content

MetadataLoadContext assembly binding behavior is documented incorrectly #113353

Closed

Description

@reflectronic

When MetadataLoadContext is resolving an assembly and its MetadataAssemblyResolver returns null, it throws an exception with this message:

<value>Could not find assembly '{0}'. Either explicitly load this assembly using a method such as LoadFromAssemblyPath() or use a MetadataAssemblyResolver that returns a valid assembly.</value>

The message suggests that 'pre-loading' the assembly with LoadFromAssemblyPath will populate the MetadataLoadContext's assembly binding cache.

The API documentation for the LoadFrom methods also suggests this is the case:

MetadataLoadContext.LoadFromAssemblyPath
Loads an assembly from a specific path on the disk and binds its assembly name to it in the MetadataLoadContext.

But these methods do not do this:

// We do not add to the _binds list because the binding list is only for assemblies that have been resolved through
// the Resolve method. This allows the resolver to have complete control over selecting the appropriate assembly
// based on Version, CultureName and PublicKeyToken.

It looks like this behavior was changed, but the documentation and exception message was not updated: 2ef74f6#diff-7a38392b94b0c17ee62172e5b642b77f0b3a1bb8d79a6488d24f1729345c46fbL49

Activity

  1. added
    untriaged
    on Mar 11, 2025
  2. dotnet-policy-service commented on Mar 11, 2025

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-reflection
    See info in area-owners.md if you want to be subscribed.

  3. added
    documentation
    and removed
    untriaged
    on Mar 17, 2025
  4. added this to the 10.0.0 milestone on Mar 17, 2025
  5. ericstj commented on Mar 17, 2025

    @ericstj
    Member

    @reflectronic would you like to propose an update to the documentation?

  6. added
    help wanted
    on Mar 17, 2025
  7. modified the milestones: 10.0.0, Future on Jul 26, 2025
  8. added a commit that references this issue on Oct 13, 2026
    04bcdaa
  9. locked and limited conversation to collaborators on Nov 13, 2026
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-System.Reflectiondocumentationhelp wanted

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions