You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, when I am running 2 scripts in a row I am getting FileLoadException "Assembly with same name is already loaded".
I am using:
nuget package Dotnet.Script 1.3.1
VS2022
.NET 6.0
In order to reproduce this issue simply call ExecuteScriptCommand.Run for two different scripts and second call should throw exception.
Sample code that shows this issue:
Program.cs
using Dotnet.Script.Core;
using Dotnet.Script.Core.Commands;
using Dotnet.Script.DependencyModel.Logging;
using DotnetScriptNet6;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Scripting.Hosting;
using Microsoft.Extensions.Logging.Abstractions;
var dotnetScriptLogHelper = new DotnetScriptLogHelper(new NullLoggerFactory());
LogFactory logFactory = dotnetScriptLogHelper.CreateLogFactory();
var fileCommand = new ExecuteScriptCommand(ScriptConsole.Default, logFactory);
var fileCommandOptions1 = new ExecuteScriptCommandOptions
(
new ScriptFile(@"script1\script1.csx"),
Array.Empty<string>(),
OptimizationLevel.Release,
Array.Empty<string>(),
false,
true
);
_ = fileCommand.Run<int, CommandLineScriptGlobals>(fileCommandOptions1).Result;
var fileCommandOptions2 = new ExecuteScriptCommandOptions
(
new ScriptFile(@"script2\script2.csx"),
Array.Empty<string>(),
OptimizationLevel.Release,
Array.Empty<string>(),
false,
true
);
_ = fileCommand.Run<int, CommandLineScriptGlobals>(fileCommandOptions2).Result;
System.AggregateException
HResult=0x80131500
Message=One or more errors occurred. (Assembly with same name is already loaded)
Source=System.Private.CoreLib
StackTrace:
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at Program.<Main>$(String[] args) in C:\Projects\testapps\DotnetScriptNet6\DotnetScriptNet6\Program.cs:line 36
This exception was originally thrown at this call stack:
System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(string)
System.Reflection.Assembly.LoadFrom(string)
Gapotchenko.FX.Reflection.AssemblyLoadPal.LoadFrom(string)
Dotnet.Script.Core.ScriptRunner.Execute<TReturn>(string, System.Collections.Generic.IEnumerable<string>) in ScriptRunner.csx
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
System.Runtime.CompilerServices.TaskAwaiter<TResult>.GetResult()
Dotnet.Script.Core.Commands.ExecuteLibraryCommand.Execute<TReturn>(Dotnet.Script.Core.Commands.ExecuteLibraryCommandOptions) in ExecuteLibraryCommand.csx
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
...
[Call Stack Truncated]
Inner Exception 1:
FileLoadException: Assembly with same name is already loaded
The text was updated successfully, but these errors were encountered:
If you add the ScriptAssemblyLoadContext to the options like this it should work
var fileCommandOptions2 = new ExecuteScriptCommandOptions
(
new ScriptFile(@"script2\script2.csx"),
Array.Empty<string>(),
OptimizationLevel.Release,
Array.Empty<string>(),
false,
true
)
{
AssemblyLoadContext = new ScriptAssemblyLoadContext()
};
Hi, when I am running 2 scripts in a row I am getting FileLoadException "Assembly with same name is already loaded".
I am using:
In order to reproduce this issue simply call ExecuteScriptCommand.Run for two different scripts and second call should throw exception.
Sample code that shows this issue:
script1\script1.csx
Console.WriteLine("Executed script1.csx");
script2\script2.csx
Console.WriteLine("Executed script2.csx");
DotnetScriptNet6.csproj
Exception details:
The text was updated successfully, but these errors were encountered: