Skip to content

Commit 7086d2d

Browse files
committed
Fix encoding 866 crash: register CodePagesEncodingProvider + add System.Text.Encoding.CodePages
Problem: Python.CreateEngine() crashes with: 'Failed to load language IronPython 2.7.12: No data is available for encoding 866' This happens because SharedIO.InitializeInput() accesses Console.InputEncoding which returns cp866 on Russian Windows. In Dynamo/Revit hosting environment or on .NET Core, cp866 is not registered, causing ArgumentException. Fix: 1. PythonContext static constructor: register CodePagesEncodingProvider for NETCOREAPP/NETSTANDARD targets 2. IronPython.csproj: add System.Text.Encoding.CodePages package for non-net45 targets (net45 has codepages built-in) Note: The DLR submodule (Src/DLR) also needs a corresponding fix in SharedIO.cs to wrap Console.InputEncoding/Output access in try-catch with UTF-8 fallback. That fix is in a separate commit in the DLR repo.
1 parent bd43cf1 commit 7086d2d

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎Directory.Build.props‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
<BaseOutputPath>$(RootDir)bin\$(Configuration)</BaseOutputPath>
104104
<OutputPath>$(BaseOutputPath)</OutputPath>
105105
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
106-
<WarningsNotAsErrors>618;429;219;1717;162;414</WarningsNotAsErrors>
106+
<WarningsNotAsErrors>618;429;219;1717;162;414;NU1900;CA1859;CA1861</WarningsNotAsErrors>
107107
<NoWarn>1591;1584;1574;1685;1573</NoWarn>
108108
<ErrorReport>prompt</ErrorReport>
109109
<WarningLevel>4</WarningLevel>

‎Src/IronPython/IronPython.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
</PackageReference>
6262
</ItemGroup>
6363

64-
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
64+
<ItemGroup Condition=" '$(TargetFramework)' != 'net45' ">
6565
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.6.0" />
6666
</ItemGroup>
6767

‎Src/IronPython/Runtime/PythonContext.cs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ namespace IronPython.Runtime
4444
public delegate int HashDelegate(object o, ref HashDelegate dlg);
4545

4646
public sealed partial class PythonContext : LanguageContext {
47+
static PythonContext() {
48+
try {
49+
#if NETCOREAPP || NETSTANDARD
50+
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
51+
#endif
52+
} catch {
53+
}
54+
}
55+
4756
internal static readonly string/*!*/ IronPythonDisplayName = CurrentVersion.DisplayName;
4857
internal const string/*!*/ IronPythonNames = "IronPython;Python;py";
4958
internal const string/*!*/ IronPythonFileExtensions = ".py";

0 commit comments

Comments
 (0)