// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
usingMicrosoft.CodeAnalysis;
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Collections.Immutable;
usingSystem.IO;
usingSystem.Reflection;
usingSystem.Reflection.Metadata;
usingSystem.Reflection.PortableExecutable;
namespaceRoslyn.Utilities
{
/// <summary>
/// Handles loading assemblies without locking the corresponding DLL on disk.
///
/// This is achieved by copying the DLL into a byte array, and then calling
/// <see cref="Assembly.Load(byte[])"/> to load the assembly from the byte array.
///
/// Does not handle multi-module assemblies.
/// </summary>
///
/// <remarks>
/// The interesting bit is that <see cref="Assembly"/> objects loaded in this way
/// are not placed in the Load or Load-From binding contexts. If one of these
/// needs a dependency to be resolved and it isn't already loaded or available in
/// the GAC, the runtime will not do any probing to find it. Since it doesn't know
/// where the assembly came from, it doesn't assume it knows how to resolve its
/// dependencies.
///
/// This means we also need to hook the <see cref="AppDomain.AssemblyResolve"/>
/// event and handle finding and loading dependencies ourselves. We also need to
/// handle loading the dependencies' dependencies, and so on.