我编写了以下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-脚本 (1.0.1版)和.NET运行时 (3.1.14版)
在执行此脚本时,我会得到以下错误。知道为什么吗?
dotnet-script HelloWorld.csxSystem.IO.FileLoadException:无法加载文件或程序集'System.Text.Encoding.CodePages,Version=5.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f7f11d50a3a‘。无法找到或加载特定文件。(0x80131621)文件名:'System.Text.Encoding.CodePages,Version=5.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a‘--> System.IO.FileLoadException:无法加载文件或程序集'System.Text.Encoding.CodePages,Version=5.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f7f11d50a3a’。在System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext,String ilPath,String niPath,ObjectHandleOnStack retAssembly,at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath),System.Reflection.Assembly.LoadFrom(String assemblyFile) at System.Reflection.Assembly.LoadFromResolveHandler(Object发件人,ResolveEventArgs args,at System.Runtime.Loader.AssemblyLoadContext.InvokeResolveEvent(ResolveEventHandler eventHandler,RuntimeAssembly汇编,String name,在System.Runtime.Loader.AssemblyLoadContext.OnAssemblyResolve(RuntimeAssembly程序集,(字符串assemblyFullName) at Submission#0.Script.Run() at Submission#0.<>d__0.MoveNext() in C:\HelloWorld.csx:line 18 --从抛出异常的前一个位置开始的堆栈跟踪的结束--在/private/var/folders/6j/4hkjjhd50fg27s933nctz0480000gn/T/tmp3iI6tV/Dotnet.Script.Core/ScriptRunner.cs:line 52中的Submission#0.Script.Run()
发布于 2021-04-21 15:31:55
我在dotnet-脚本回购上创建了一个问题,并从开发人员那里得到了答案。所有细节请参阅该问题。。
我得到的答案是,DotNet-ScriptVersion1.0.1预加载了System.Text.Encoding.CodePages的4.7.1版本,这意味着一个较新的专业无法解决。
https://stackoverflow.com/questions/67131095
复制相似问题