IronLanguages / ironpython2

Implementation of the Python programming language for .NET Framework; built on top of the Dynamic Language Runtime (DLR).

Home Page:http://ironpython.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Invalid assembly qualified name" exception when calling Python.CreateEngine() on .NET 5.0+ when using Thai (th-TH) culture

waltdestler opened this issue · comments

I've run into a strange and highly-specific yet trivially-reproducible problem that is preventing IronPython from working: If I try to call Python.CreateEngine() with the current thread's culture set to Thai (th-TH; either inherited from OS settings or set manually via C# code), then it throws the following exception:

System.ArgumentException: Invalid assembly qualified name 'IronPython.Runtime.PythonContext, IronPython, Version=2.7.11.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1' (Parameter 'languageTypeName')
at Microsoft.Scripting.Utils.AssemblyQualifiedTypeName.ParseArgument(String str, String argumentName)
at Microsoft.Scripting.Runtime.DlrConfiguration.AddLanguage(String languageTypeName, String displayName, IList1 names, IList1 fileExtensions, IDictionary2 options, String paramName) at Microsoft.Scripting.Runtime.DlrConfiguration.AddLanguage(String languageTypeName, String displayName, IList1 names, IList1 fileExtensions, IDictionary2 options)
at Microsoft.Scripting.Hosting.ScriptRuntimeSetup.ToConfiguration()
at Microsoft.Scripting.Hosting.ScriptRuntime..ctor(ScriptRuntimeSetup setup)
at IronPython.Hosting.Python.CreateRuntime()
at IronPython.Hosting.Python.CreateEngine()
at Program.Main() in C:\Users\walt\Desktop\CSTest\Program.cs:line 10

Here is a complete program that reproduces the issue:

using System;
using System.Globalization;
using IronPython.Hosting;

class Program
{
    public static void Main()
    {
        CultureInfo.CurrentCulture = new CultureInfo("th-TH");
        Python.CreateEngine();
        Console.WriteLine("Worked.");
    }
}

I am able to reproduce this when targeting .NET 5.0 and the latest .NET 6 preview, but NOT when targeting .NET Core 3.1. (I have not tried earlier versions.) I am able to reproduce this with every version of IronPython that I've tried, including 3.4.0-alpha, 2.7.11, and a handful of others. I am not aware of any cultures other than Thai that cause this issue, though I haven't tested exhaustively and would be surprised if it was the only one to cause this issue.

Any ideas what's going on? I suspect this could be a .NET bug introduced in 5.0 and not an IronPython bug, but I haven't had this issue with any other libraries, so I'm not sure.

Hmm, "I".IndexOf(",") is returning 0 with .NET 5. Must make some sort of linguistic sense? Probably related to the change in behavior with string comparison: https://docs.microsoft.com/en-us/dotnet/standard/base-types/string-comparison-net-5-plus

Looks like this particular failure will need to be fixed in the DLR.