Skip to content

Commit a81c8ef

Browse files
committed
Custom assembly load context can be null and should not be used in this case.
1 parent 5b76560 commit a81c8ef

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Dotnet.Script.Core/ScriptRunner.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ public async Task<TReturn> Execute<TReturn>(string dllPath, IEnumerable<string>
5555
var assembly = assemblyLoadPal.LoadFrom(dllPath); // this needs to be called prior to 'AssemblyLoadPal.Resolving' event handler added
5656

5757
#if NETCOREAPP
58-
using var assemblyAutoLoader = new AssemblyAutoLoader(assemblyLoadContext);
59-
assemblyAutoLoader.AddAssembly(assembly);
58+
using var assemblyAutoLoader = assemblyLoadContext != null ? new AssemblyAutoLoader(assemblyLoadContext) : null;
59+
assemblyAutoLoader?.AddAssembly(assembly);
6060
#endif
6161

6262
#if NETCOREAPP3_0_OR_GREATER
63-
using var contextualReflectionScope = assemblyLoadContext.EnterContextualReflection();
63+
using var contextualReflectionScope = assemblyLoadContext != null ? assemblyLoadContext.EnterContextualReflection() : default;
6464
#endif
6565

6666
Assembly OnResolve(AssemblyLoadPal sender, AssemblyLoadPal.ResolvingEventArgs args) => ResolveAssembly(sender, args, runtimeDepsMap);

0 commit comments

Comments
 (0)