Skip to content

MetadataLoadContext assembly binding behavior is documented incorrectly #113353

Open
@reflectronic

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.ReflectiondocumentationDocumentation bug or enhancement, does not impact product or test codehelp wanted[up-for-grabs] Good issue for external contributors

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions