Fix encoding 866 crash: register CodePagesEncodingProvider + SharedIO fallback - #851
Open
dronov-dmitry wants to merge 1 commit into
Open
Fix encoding 866 crash: register CodePagesEncodingProvider + SharedIO fallback#851dronov-dmitry wants to merge 1 commit into
dronov-dmitry wants to merge 1 commit into
Conversation
…em.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.
Author
|
@dotnet-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Python.CreateEngine()crashes with:This happens in hosting environments like Dynamo (Autodesk Revit) or on .NET Core where cp866 encoding is not registered by default.
Root cause
SharedIO.InitializeInput()accessesConsole.InputEncodingwithout error handling. On Russian Windows this returns cp866, but in certain hosting environments the codepage data is unavailable, causingArgumentException.Fix (2 parts)
Part 1: DLR — SharedIO fallback
File:
Src/DLR/Src/Microsoft.Scripting/Runtime/SharedIO.csAdded
TryGetConsoleEncoding()helper that wraps console encoding access in try-catch with UTF-8 fallback:Applied to:
InitializeInput()—Console.InputEncoding→ fallbackEncoding.UTF8InitializeOutput()—Console.Out→ fallbackTextWriter.NullInitializeErrorOutput()—Console.Error→ fallbackTextWriter.NullFull diff for DLR submodule:
Part 2: IronPython — RegisterProvider (this PR)
File:
Src/IronPython/Runtime/PythonContext.csAdded static constructor that registers
CodePagesEncodingProviderfor .NET Core/Standard:File:
Src/IronPython/IronPython.csprojAdded
System.Text.Encoding.CodePagespackage for non-net45 targets:Testing
All tests pass (C# host simulating Dynamo + IronPython scripts):
Compatibility