|
4 | 4 | using System.Linq;
|
5 | 5 | using System.Reflection;
|
6 | 6 | using System.Runtime.InteropServices;
|
7 |
| -using System.Runtime.Loader; |
8 | 7 | using Microsoft.CodeAnalysis;
|
9 | 8 | using Microsoft.CodeAnalysis.CSharp.Scripting;
|
10 | 9 | using Microsoft.CodeAnalysis.Scripting;
|
@@ -134,8 +133,8 @@ public virtual ScriptCompilationContext<TReturn> CreateCompilationContext<TRetur
|
134 | 133 | }
|
135 | 134 | }
|
136 | 135 |
|
137 |
| - AssemblyLoadContext.Default.Resolving += |
138 |
| - (assemblyLoadContext, assemblyName) => MapUnresolvedAssemblyToRuntimeLibrary(dependencyMap, assemblyLoadContext, assemblyName); |
| 136 | + AppDomain.CurrentDomain.AssemblyResolve += |
| 137 | + (sender, args) => MapUnresolvedAssemblyToRuntimeLibrary(dependencyMap, args); |
139 | 138 |
|
140 | 139 | // when processing raw code, make sure we inject new lines after preprocessor directives
|
141 | 140 | string code;
|
@@ -164,14 +163,15 @@ public virtual ScriptCompilationContext<TReturn> CreateCompilationContext<TRetur
|
164 | 163 | return new ScriptCompilationContext<TReturn>(script, context.Code, loader, opts);
|
165 | 164 | }
|
166 | 165 |
|
167 |
| - private Assembly MapUnresolvedAssemblyToRuntimeLibrary(IDictionary<string, RuntimeAssembly> dependencyMap, AssemblyLoadContext loadContext, AssemblyName assemblyName) |
| 166 | + private Assembly MapUnresolvedAssemblyToRuntimeLibrary(IDictionary<string, RuntimeAssembly> dependencyMap, ResolveEventArgs args) |
168 | 167 | {
|
| 168 | + var assemblyName = new AssemblyName(args.Name); |
169 | 169 | if (dependencyMap.TryGetValue(assemblyName.Name, out var runtimeAssembly))
|
170 | 170 | {
|
171 | 171 | if (runtimeAssembly.Name.Version > assemblyName.Version)
|
172 | 172 | {
|
173 | 173 | Logger.Log($"Redirecting {assemblyName} to {runtimeAssembly.Name}");
|
174 |
| - return loadContext.LoadFromAssemblyPath(runtimeAssembly.Path); |
| 174 | + return Assembly.LoadFile(runtimeAssembly.Path); |
175 | 175 | }
|
176 | 176 | }
|
177 | 177 |
|
|
0 commit comments