Fix encoding 866 crash: fallback to UTF-8 when console encoding unavailable - #364
Closed
dronov-dmitry wants to merge 1 commit into
Closed
dronov-dmitry wants to merge 1 commit into
dronov-dmitry wants to merge 1 commit into
Conversation
…coding unavailable SharedIO.InitializeInput/Output/ErrorOutput accessed Console.InputEncoding and Console.Out/Console.Error without error handling. On systems where cp866 (or other console encodings) are not registered (e.g. Dynamo/Revit hosting environment, .NET Core), this threw ArgumentException: 'No data is available for encoding 866' Added TryGetConsoleEncoding() helper that wraps encoding access in try-catch and falls back to Encoding.UTF8 / TextWriter.Null when the console encoding is unavailable.
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
SharedIO.InitializeInput()accessesConsole.InputEncodingwithout error handling. On Russian Windows this returns cp866, but in hosting environments like Dynamo (Autodesk Revit) or on .NET Core, the codepage data is unavailable, causing:This crashes
Python.CreateEngine()in IronPython.Fix
Added
TryGetConsoleEncoding()helper that wraps console encoding access in try-catch with fallback:Applied to:
InitializeInput()—Console.InputEncoding/Encoding.Default→ fallbackEncoding.UTF8InitializeOutput()—Console.Out→ fallbackTextWriter.NullInitializeErrorOutput()—Console.Error→ fallbackTextWriter.NullCompanion PR
This fix works together with IronLanguages/ironpython2#851 which adds
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance)inPythonContextstatic constructor for .NET Core/Standard.Testing
Verified with C# host simulating Dynamo environment — all tests pass.