Skip to content

Commit fad86f6

Browse files
committed
Enabled assembly isolation for interactive script execution.
1 parent 68c5645 commit fad86f6

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/Dotnet.Script/Program.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.IO;
1212
using System.Linq;
1313
using System.Runtime.InteropServices;
14+
using System.Runtime.Loader;
1415
using System.Threading.Tasks;
1516

1617
namespace Dotnet.Script
@@ -247,7 +248,7 @@ private static int Wain(string[] args)
247248
nocache.HasValue()
248249
)
249250
{
250-
AssemblyLoadContext = new ScriptAssemblyLoadContext()
251+
AssemblyLoadContext = CreateAssemblyLoadContext()
251252
};
252253

253254
var fileCommand = new ExecuteScriptCommand(ScriptConsole.Default, logFactory);
@@ -265,16 +266,24 @@ private static int Wain(string[] args)
265266

266267
private static async Task<int> RunInteractive(bool useRestoreCache, LogFactory logFactory, string[] packageSources)
267268
{
268-
var options = new ExecuteInteractiveCommandOptions(null, Array.Empty<string>(), packageSources);
269+
var options = new ExecuteInteractiveCommandOptions(null, Array.Empty<string>(), packageSources)
270+
{
271+
AssemblyLoadContext = CreateAssemblyLoadContext()
272+
};
269273
await new ExecuteInteractiveCommand(ScriptConsole.Default, logFactory).Execute(options);
270274
return 0;
271275
}
272276

273277
private async static Task<int> RunInteractiveWithSeed(string file, LogFactory logFactory, string[] arguments, string[] packageSources)
274278
{
275-
var options = new ExecuteInteractiveCommandOptions(new ScriptFile(file), arguments, packageSources);
279+
var options = new ExecuteInteractiveCommandOptions(new ScriptFile(file), arguments, packageSources)
280+
{
281+
AssemblyLoadContext = CreateAssemblyLoadContext()
282+
};
276283
await new ExecuteInteractiveCommand(ScriptConsole.Default, logFactory).Execute(options);
277284
return 0;
278285
}
286+
287+
static AssemblyLoadContext CreateAssemblyLoadContext() => new ScriptAssemblyLoadContext();
279288
}
280289
}

0 commit comments

Comments
 (0)