ironpython2 icon indicating copy to clipboard operation
ironpython2 copied to clipboard

IronPython.Hosting.Python.CreateEngine in Blazor 5 - WebAssembly .Net5.

Open JimmyHeartbreaker opened this issue 4 years ago • 7 comments

Description

I am using a 3rd party library targeting .netstandard2.0 in Blazor which is built on web assembly which uses mono. This library uses IronPython. In Blazor version 3.2.1 IronPython works but in 5.0.2 it does not.

Steps to Reproduce

Create a Blazor .net 5 app. Run IronPython.Hosting.Python.CreateEngine(IDictionary`2 options)

See error below - is it possible to disable console input?

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: failed to evaluate assumptions. CorrelationId=="5f178588-9796-4c4f-968a-4cdd8079e303", System.Reflection.TargetInvocationException: Failed to load language 'IronPython 2.7.11': The type initializer for 'Microsoft.Scripting.Utils.ConsoleInputStream' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Microsoft.Scripting.Utils.ConsoleInputStream' threw an exception. ---> System.PlatformNotSupportedException: Operation is not supported on this platform. at System.ConsolePal.OpenStandardInput() at System.Console.OpenStandardInput() at Microsoft.Scripting.Utils.ConsoleInputStream..ctor() at Microsoft.Scripting.Utils.ConsoleInputStream..cctor() --- End of inner exception stack trace --- at Microsoft.Scripting.Runtime.SharedIO.InitializeInput() at Microsoft.Scripting.Runtime.SharedIO.get_InputReader() at Microsoft.Scripting.Runtime.SharedIO.GetReader(Encoding& encoding) at IronPython.Runtime.PythonFile.CreateConsoleReader() at IronPython.Runtime.PythonFile.InitializeConsole(SharedIO io, ConsoleStreamType type, String name) at IronPython.Runtime.PythonFile.CreateConsole(PythonContext context, SharedIO io, ConsoleStreamType type, String name) at IronPython.Runtime.PythonContext.SetStandardIO() at IronPython.Runtime.PythonContext.InitializeSystemState() at IronPython.Runtime.PythonContext..ctor(ScriptDomainManager manager, IDictionary2 options) at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, Object[] parameters, Boolean wrapExceptions) --- 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(IDictionary2 options)

JimmyHeartbreaker avatar Jan 24 '21 23:01 JimmyHeartbreaker

Thanks for the report. I've always wanted to try IronPython in Blazor but never got around to it. I was able to reproduce the issue but I'm having a hard time attaching a debugger to the project. Would be nice if it worked out of the box, but for now, here's a potential workaround for the issue:

var runtime = Python.CreateRuntime();
runtime.IO.SetInput(new MemoryStream(), Encoding.Default);
var engine = Python.GetEngine(runtime);

slozier avatar Jan 26 '21 14:01 slozier

for me, the debugger takes a few moments to attach (the first run through never debugs for me) and occasionally not at all. Its a bit flaky to say the least. I use vanilla chrome.

Thx, I will try the work around. [edit] Works!

JimmyHeartbreaker avatar Jan 26 '21 15:01 JimmyHeartbreaker

I got path1 Value can not be null exception when trying the work around. Can anyone give me a small working sample of the work around

syedqutub avatar Nov 13 '21 16:11 syedqutub

@syedqutub I'm guessing you're running into this issue: https://github.com/IronLanguages/ironpython2/issues/762

slozier avatar Nov 15 '21 14:11 slozier

@syedqutub I'm guessing you're running into this issue: #762

Yuo. Any work around?

syedqutub avatar Nov 16 '21 13:11 syedqutub

No workaround that I know of - will need a release to fix.

slozier avatar Nov 17 '21 16:11 slozier

@slozier @JimmyHeartbreaker Fixed IronPython3, might have fixed 2 as well. https://github.com/IronLanguages/dlr/pull/256

TwoUnderscorez avatar May 07 '22 17:05 TwoUnderscorez