- Notifications
You must be signed in to change notification settings - Fork178
Closed
Description
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;script1\script1.csx
Console.WriteLine("Executed script1.csx");script2\script2.csx
Console.WriteLine("Executed script2.csx");DotnetScriptNet6.csproj
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net6.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>disable</Nullable> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> <LangVersion>latest</LangVersion> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <LangVersion>latest</LangVersion> </PropertyGroup> <ItemGroup> <None Include="..\.editorconfig" Link=".editorconfig" /> </ItemGroup> <ItemGroup> <PackageReference Include="Dotnet.Script" Version="1.3.1" /> </ItemGroup> <ItemGroup> <None Update="script1\script1.csx"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> <None Update="script2\script2.csx"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> </ItemGroup></Project>Exception details:
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 loadedMetadata
Metadata
Assignees
Labels
No labels