c# - 使用 .NET Core 3.1 运行 C# 脚本时出现 FileLoadException
问题描述
我编写了以下 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。
解决方案
我在dotnet-script repo上创建了一个问题,并从开发人员那里得到了答案。有关所有详细信息,请参阅问题。
我得到的答案是 dotnet-script 1.0.1 版预加载了 System.Text.Encoding.CodePages 的 4.7.1 版,这意味着无法解决较新的专业。
推荐阅读
- c# - 在选择组合框时向 datagridview 中的下一个单元格添加值并删除选定的组合值
- oauth - 在 OIM 中配置软件和集成之间的确切区别是什么
- ios - (Swift)如何使用触摸按钮更改 pageviewcontroller 中的视图
- spring - 检索属性 pom.xml 的值
- c# - DropDown AutoPostBack 在 IIS 上不起作用
- javascript - 从弹簧控制器获取数据
- javascript - 在滚动javascript上更改多个图像背景
- go - 如何在 golang 中更新 bigquery 行
- apache-pig - 使用 Apache Pig 过滤日期
- ios - 为 iOS/Xcode 的 UITextView 手动格式化以 http 或 https 开头的 url