2

I wrote the following C# script (HelloWorld.csx file):

#! "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();

I'm using dotnet-script (version 1.0.1) and .NET Runtime (version 3.1.14)

When executing this script, I get the following error. Any idea why?

dotnet-script HelloWorld.csx

System.IO.FileLoadException: Could not load file or assembly 'System.Text.Encoding.CodePages, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Could not find or load a specific file. (0x80131621) File name: 'System.Text.Encoding.CodePages, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileLoadException: Could not load file or assembly 'System.Text.Encoding.CodePages, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly) at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath) at System.Reflection.Assembly.LoadFrom(String assemblyFile) at System.Reflection.Assembly.LoadFromResolveHandler(Object sender, ResolveEventArgs args) at System.Runtime.Loader.AssemblyLoadContext.InvokeResolveEvent(ResolveEventHandler eventHandler, RuntimeAssembly assembly, String name) at System.Runtime.Loader.AssemblyLoadContext.OnAssemblyResolve(RuntimeAssembly assembly, String assemblyFullName) at Submission#0.Script.Run() at Submission#0.<>d__0.MoveNext() in C:\HelloWorld.csx:line 18 --- End of stack trace from previous location where exception was thrown --- at Dotnet.Script.Core.ScriptRunner.Execute[TReturn](String dllPath, IEnumerable`1 commandLineArgs) in /private/var/folders/6j/4hkjjhd50fg27s933nctz0480000gn/T/tmp3iI6tV/Dotnet.Script.Core/ScriptRunner.cs:line 52

3
  • Just tried replicating this but it worked for me. I installed dotnet-script as a global tool, created a csx file as shown above and then executed with dotnet-script code-pages.csx - no errors. Not helpful I know, but wonder if it is a permissions issue with wherever dotnet script is caching nuget packages? Commented Apr 17, 2021 at 16:23
  • @phil_rawlings Which runtime are you using? You can know which runtimes are installed by running this command: dotnet --list-runtimes Commented Apr 19, 2021 at 13:01
  • 2.1.26, 2.127, 3.0.0-preview8-28405-07, 3.1.13, 3.1.14, 5.0.4 and 5.0.5 Commented Apr 20, 2021 at 13:44

1 Answer 1

1

I created an issue on the dotnet-script repo and I got an answer from the dev. Refer to the issue for all the details.

The answer I got is that dotnet-script version 1.0.1 preloads version 4.7.1 of System.Text.Encoding.CodePages which means a newer major cannot be resolved.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.