7
7
using Dotnet . Script . DependencyModel . Environment ;
8
8
using Dotnet . Script . DependencyModel . Logging ;
9
9
using Dotnet . Script . DependencyModel . Runtime ;
10
+ using Gapotchenko . FX . Reflection ;
10
11
using Microsoft . CodeAnalysis . CSharp . Scripting . Hosting ;
11
12
using Microsoft . CodeAnalysis . Scripting ;
12
13
using Microsoft . CodeAnalysis . Scripting . Hosting ;
@@ -30,13 +31,15 @@ public ScriptRunner(ScriptCompiler scriptCompiler, LogFactory logFactory, Script
30
31
31
32
public async Task < TReturn > Execute < TReturn > ( string dllPath , IEnumerable < string > commandLineArgs )
32
33
{
34
+ var assemblyLoaderPal = AssemblyLoadPal . ForCurrentAppDomain ;
35
+
33
36
var runtimeDeps = ScriptCompiler . RuntimeDependencyResolver . GetDependenciesForLibrary ( dllPath ) ;
34
37
var runtimeDepsMap = ScriptCompiler . CreateScriptDependenciesMap ( runtimeDeps ) ;
35
- var assembly = Assembly . LoadFrom ( dllPath ) ; // this needs to be called prior to 'AppDomain.CurrentDomain.AssemblyResolve' event handler added
38
+ var assembly = assemblyLoaderPal . LoadFrom ( dllPath ) ; // this needs to be called prior to 'AppDomain.CurrentDomain.AssemblyResolve' event handler added
36
39
37
- Assembly OnResolve ( object sender , ResolveEventArgs args ) => ResolveAssembly ( args , runtimeDepsMap ) ;
40
+ Assembly OnResolve ( AssemblyLoadPal sender , AssemblyLoadPal . ResolvingEventArgs args ) => ResolveAssembly ( sender , args , runtimeDepsMap ) ;
38
41
39
- AppDomain . CurrentDomain . AssemblyResolve += OnResolve ;
42
+ assemblyLoaderPal . Resolving += OnResolve ;
40
43
try
41
44
{
42
45
var type = assembly . GetType ( "Submission#0" ) ;
@@ -64,7 +67,7 @@ public async Task<TReturn> Execute<TReturn>(string dllPath, IEnumerable<string>
64
67
}
65
68
finally
66
69
{
67
- AppDomain . CurrentDomain . AssemblyResolve -= OnResolve ;
70
+ assemblyLoaderPal . Resolving -= OnResolve ;
68
71
}
69
72
}
70
73
@@ -97,12 +100,11 @@ public virtual async Task<TReturn> Execute<TReturn, THost>(ScriptCompilationCont
97
100
return ProcessScriptState ( scriptResult ) ;
98
101
}
99
102
100
- internal Assembly ResolveAssembly ( ResolveEventArgs args , Dictionary < string , RuntimeAssembly > runtimeDepsMap )
103
+ internal Assembly ResolveAssembly ( AssemblyLoadPal sender , AssemblyLoadPal . ResolvingEventArgs args , Dictionary < string , RuntimeAssembly > runtimeDepsMap )
101
104
{
102
- var assemblyName = new AssemblyName ( args . Name ) ;
103
- var result = runtimeDepsMap . TryGetValue ( assemblyName . Name , out RuntimeAssembly runtimeAssembly ) ;
105
+ var result = runtimeDepsMap . TryGetValue ( args . Name . Name , out RuntimeAssembly runtimeAssembly ) ;
104
106
if ( ! result ) return null ;
105
- var loadedAssembly = Assembly . LoadFrom ( runtimeAssembly . Path ) ;
107
+ var loadedAssembly = sender . LoadFrom ( runtimeAssembly . Path ) ;
106
108
return loadedAssembly ;
107
109
}
108
110
0 commit comments