我编写了以下 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。