[netcore] Implement referenced assembly resolving and ALC.GetLoadContext (mono/mono...
authorAleksey Kliger (λgeek) <alklig@microsoft.com>
Fri, 2 Aug 2019 18:06:44 +0000 (14:06 -0400)
committerGitHub <noreply@github.com>
Fri, 2 Aug 2019 18:06:44 +0000 (14:06 -0400)
commitad1bded7e4780e2214acf405a1ec392161378dfc
tree39eeed5ca1f42a8ebfe04f9e96190054031a2d3d
parent3d09423d9fbb85f433cf2a6cfa2a472883ac3d90
[netcore] Implement referenced assembly resolving and ALC.GetLoadContext (mono/mono#15946)

* [netcore] Implement GetLoadContext

* [netcore] Implement ALC-aware referenced assembly resolution.

The process is described in
https://docs.microsoft.com/en-us/dotnet/api/system.runtime.loader.assemblyloadcontext?view=netcore-3.0#usage-in-the-runtime

We try four things until one of them returns a non-null assembly.

1. Check if the assembly is already loaded in the ALC of the requesting
assembly.
2. If the ALC is not the default ALC, invoke the Load override.
3. Try the default ALC (TPA - trusted platform assemblies) loading.
4. Invoke the Resolving event of the original ALC.

The implementation borrows some managed code from
https://github.com/dotnet/coreclr/blob/mono/mono@8ba2e15201361402acd0ae9710bd37d50785cdfa/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs#L84-L187

It would be nice if that code was shared between the runtimes.

* [runtime] Implement mono_assembly_name_culture_is_neutral

* [netcore] Add mono_alc_invoke_resolve_using_resolve_satellite

* [netcore] Use ResolveSatelliteAssembly for satellite assembly refs

* [netcore] Some AssemblyLoadContextTest tests now pass

System.Runtime.Loader.Tests.AssemblyLoadContextTest.PublicConstructor_Default
System.Runtime.Loader.Tests.AssemblyLoadContextTest.GetAssemblyNameTest_NullParameter
System.Runtime.Loader.Tests.AssemblyLoadContextTest.LoadFromAssemblyName_AssemblyNotFound
System.Runtime.Loader.Tests.AssemblyLoadContextTest.PublicConstructor_Theory (with isCollectible: False)
System.Runtime.Loader.Tests.AssemblyLoadContextTest.GetAssemblyNameTest_ValidAssembly
System.Runtime.Loader.Tests.AssemblyLoadContextTest.GetLoadContextTest_SystemPrivateCorelibAssembly
System.Runtime.Loader.Tests.AssemblyLoadContextTest.DefaultAssemblyLoadContext_Properties
System.Runtime.Loader.Tests.AssemblyLoadContextTest.GetAssemblyNameTest_AssemblyNotFound
System.Runtime.Loader.Tests.AssemblyLoadContextTest.GetLoadContextTest_ValidTrustedPlatformAssembly

Commit migrated from https://github.com/mono/mono/commit/2f2f6c104b2a0115a7fb1ab24673b587c27e4365
src/mono/mono/metadata/assembly-internals.h
src/mono/mono/metadata/assembly-load-context.c
src/mono/mono/metadata/assembly.c
src/mono/mono/metadata/domain.c
src/mono/mono/metadata/icall-def-netcore.h
src/mono/mono/metadata/loader-internals.h
src/mono/netcore/CoreFX.issues.rsp
src/mono/netcore/System.Private.CoreLib/src/LinkerDescriptor/System.Private.CoreLib.xml
src/mono/netcore/System.Private.CoreLib/src/System.Reflection/RuntimeAssembly.cs
src/mono/netcore/System.Private.CoreLib/src/System.Runtime.Loader/AssemblyLoadContext.cs