/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Scripting/Core/Hosting/AssemblyLoader/DesktopAssemblyLoaderImpl.cs
56 строк
2 KB
Tomáš Matoušek
Remove assembly loading light-up from scripting (#74409)
25 июл 2024, 03:39
Не верифицирован
25 июл 2024, 03:39
5998125
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. #if !NET using System; using System.IO; using System.Reflection; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Scripting.Hosting { internal sealed class DesktopAssemblyLoaderImpl : AssemblyLoaderImpl { public DesktopAssemblyLoaderImpl(InteractiveAssemblyLoader loader) : base(loader) { AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; } public override void Dispose() { AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve; } private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) => Loader.ResolveAssembly(args.Name, args.RequestingAssembly); public override Assembly LoadFromStream(Stream peStream, Stream pdbStream) { var peImage = new byte[peStream.Length]; peStream.TryReadAll(peImage, 0, peImage.Length); if (pdbStream != null) { var pdbImage = new byte[pdbStream.Length]; pdbStream.TryReadAll(pdbImage, 0, pdbImage.Length); return Assembly.Load(peImage, pdbImage); } return Assembly.Load(peImage); } public override AssemblyAndLocation LoadFromPath(string path) { // An assembly is loaded into CLR's Load Context if it is in the GAC, otherwise it's loaded into No Context via Assembly.LoadFile(string). // Assembly.LoadFile(string) automatically redirects to GAC if the assembly has a strong name and there is an equivalent assembly in GAC. var assembly = Assembly.LoadFile(path); return new AssemblyAndLocation(assembly, assembly.Location, assembly.GlobalAssemblyCache); } } } #endif