dotnet/runtime

MetadataLoadContext assembly binding behavior is documented incorrectly

Open

#113.353 geöffnet am 11. März 2025

Auf GitHub ansehen
 (2 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)C# (5.445 Forks)batch import
area-System.Reflectiondocumentationhelp wanted

Repository-Metriken

Stars
 (17.886 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 12T 11h) (661 gemergte PRs in 30 T)

Beschreibung

When MetadataLoadContext is resolving an assembly and its MetadataAssemblyResolver returns null, it throws an exception with this message: https://github.com/dotnet/runtime/blob/a49ed697037bad503e32daa23f4339ebfb8962ea/src/libraries/System.Reflection.MetadataLoadContext/src/Resources/Strings.resx#L181 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: https://github.com/dotnet/runtime/blob/a49ed697037bad503e32daa23f4339ebfb8962ea/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/MetadataLoadContext.Loading.cs#L47-L49

It looks like this behavior was changed, but the documentation and exception message was not updated: https://github.com/dotnet/runtime/commit/2ef74f6be9ac1a70902facdc4047c49682e75005#diff-7a38392b94b0c17ee62172e5b642b77f0b3a1bb8d79a6488d24f1729345c46fbL49

Contributor Guide