繁体   English   中英

使用 .NET Core 3.1 运行 C# 脚本时出现 FileLoadException

[英]FileLoadException when running C# script with .NET Core 3.1

我编写了以下 C# 脚本(HelloWorld.csx 文件):

#! "netcoreapp3.1"
#r "nuget: System.Text.Encoding.CodePages, 5.0.0"

public class Script
{
    public static void Run()
    {
        try
        {
            System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine(ex.ToString());
        }
    }
}

Script.Run();

我正在使用dotnet-script (版本 1.0.1)和.NET 运行时(版本 3.1.14)

执行此脚本时,出现以下错误。 知道为什么吗?

dotnet-script HelloWorld.csx

System.IO.FileLoadException:无法加载文件或程序集“System.Text.Encoding.CodePages,版本=5.0.0.0,文化=中性,PublicKeyToken=b03f5f7f11d50a3a”。 无法找到或加载特定文件。 (0x80131621)文件名:'System.Text.Encoding.CodePages,版本=5.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a'---> System.IO.FileLoadException:无法加载文件或程序集'System.Text。 Encoding.CodePages,版本=5.0.0.0,文化=中性,PublicKeyToken=b03f5f7f11d50a3a'。 在 System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly) 在 System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath) 在 System.Reflection.Assembly.LoadFrom(String assemblyFile) 在System.Reflection.Assembly.LoadFromResolveHandler(Object sender, ResolveEventArgs args) 在 System.Runtime.Loader.AssemblyLoadContext.InvokeResolveEvent(ResolveEventHandler eventHandler, RuntimeAssembly 程序集, 字符串名称) 在 System.Runtime.Loader.AssemblyLoadContext.OnAssemblyResolve(RuntimeAssembly 程序集, 字符串程序集FullName ) 在 Submission#0.Script.Run() 在 Submission#0.<>d__0.MoveNext() 在 C:\HelloWorld.csx:line 18 --- 堆栈跟踪从上一个引发异常的位置结束---在 /private/var/folders/6j/4hkjjhd50fg27s933nctz0480 中的 Dotnet.Script.Core.ScriptRunner.Execute[TReturn](String dllPath, IEnumerable`1 commandLineArgs) 000gn/T/tmp3iI6tV/Dotnet.Script.Core/ScriptRunner.cs:第 52 行

我在dotnet-script repo上创建了一个问题,并从开发人员那里得到了答案。 有关所有详细信息,请参阅问题

我得到的答案是 dotnet-script 1.0.1 版预加载了 System.Text.Encoding.CodePages 的 4.7.1 版,这意味着无法解决较新的专业。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM