Skip to content

IronPython3 PlatformNotSupportedException in .NET WASM #1952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hawkerm opened this issue Apr 25, 2025 · 2 comments
Open

IronPython3 PlatformNotSupportedException in .NET WASM #1952

hawkerm opened this issue Apr 25, 2025 · 2 comments

Comments

@hawkerm
Copy link

hawkerm commented Apr 25, 2025

Maybe this is a regression based on the PR here, seemingly indicating that it was the fix to make IronPython3 work with Blazor: IronLanguages/dlr#256
Though this issue remained open on IronPython2 (but again indicated the scenario should work in IronPython3): IronLanguages/ironpython2#769

I'm in an Uno Platform WASM context (should be the same as Blazor). And when I tried to call CreateEngine I got this exception (which looks like it's trying to find the console, though that was what the above PR was supposed to fix?):

System.Reflection.TargetInvocationException: Failed to load language 'IronPython 3.4.2': Operation is not supported on this platform.
 ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
   at System.ConsolePal.get_InputEncoding()
   at System.Console.get_InputEncoding()
   at Microsoft.Scripting.Runtime.SharedIO.InitializeInput()
   at Microsoft.Scripting.Runtime.SharedIO.get_InputEncoding()
   at IronPython.Modules.PythonIOModule.CreateConsole(PythonContext context, SharedIO io, ConsoleStreamType type, String name, StreamBox& sio)
   at IronPython.Runtime.PythonContext.SetStandardIO()
   at IronPython.Runtime.PythonContext.InitializeSystemState()
   at IronPython.Runtime.PythonContext..ctor(ScriptDomainManager manager, IDictionary`2 options)
   at System.Object.InvokeStub_PythonContext..ctor(Object , Span`1 )
   at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   --- End of inner exception stack trace ---
   at Microsoft.Scripting.Runtime.LanguageConfiguration.LoadLanguageContext(ScriptDomainManager domainManager, Boolean& alreadyLoaded)
   at Microsoft.Scripting.Runtime.DlrConfiguration.LoadLanguageContext(ScriptDomainManager manager, LanguageConfiguration config)
   at Microsoft.Scripting.Runtime.DlrConfiguration.TryLoadLanguage(ScriptDomainManager manager, AssemblyQualifiedTypeName& providerName, LanguageContext& language)
   at Microsoft.Scripting.Runtime.ScriptDomainManager.GetLanguageByTypeName(String providerAssemblyQualifiedTypeName)
   at Microsoft.Scripting.Hosting.ScriptRuntime.GetEngineByTypeName(String assemblyQualifiedTypeName)
   at IronPython.Hosting.Python.GetEngine(ScriptRuntime runtime)
   at IronPython.Hosting.Python.CreateEngine()

Perhaps some similar try/catch fallback helper logic to IronLanguages/dlr#256 needs to be implemented here?

private void SetStandardIO() {
SharedIO io = DomainManager.SharedIO;
io.ConsoleSupportLevel = PythonOptions.ConsoleSupportLevel;
var stdin = PythonIOModule.CreateConsole(this, io, ConsoleStreamType.Input, "<stdin>", out StreamBox sstdin);
var stdout = PythonIOModule.CreateConsole(this, io, ConsoleStreamType.Output, "<stdout>", out StreamBox sstdout);
var stderr = PythonIOModule.CreateConsole(this, io, ConsoleStreamType.ErrorOutput, "<stderr>", out StreamBox sstderr);

I don't need input in my scenario, and plan to redirect the output already. Though not sure if there'd be other blockers beyond this.

Already been poking at this too late today, but will see if I can build the repo and investigate, VS doesn't seem to let me step-in to the function in the WASM debug context for some reason.

@slozier
Copy link
Contributor

slozier commented Apr 25, 2025

You can set the ConsoleSupportLevel to None when you create your engine. You might also need to use the NoImportLib option:

var engine = Python.CreateEngine(new Dictionary<string, object> {
         {"ConsoleSupportLevel", "None"},
         {"NoImportLib", true},
    });

@hawkerm
Copy link
Author

hawkerm commented Apr 26, 2025

Thanks @slozier, much appreciated! Just turning off the ConsoleSupportLevel option seems to work now for the simple stuff I'm doing.

Will report if I have any other issues, could still be good to call out in the docs somewhere, I didn't see anything on configuration options for instance. And/or wrap the exception to bubble up that as a suggestion within the error itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants