Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Assembly with same name is already loaded exception when run second script #671

Closed
@nowwwak

Description

@nowwwak

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:

  1. 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;
  1. script1\script1.csx
    Console.WriteLine("Executed script1.csx");

  2. script2\script2.csx
    Console.WriteLine("Executed script2.csx");

  3. 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 loaded

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp