ironpython3
ironpython3 copied to clipboard
Exception on using example in GITHUB encoding 850
Prerequisites
The issue tracker is used to report bugs and request new features, NOT to ask questions.
Questions should be posted to the users mailing list which can be accessed at https://ironpython.groups.io/g/users.
- [ X] Are you running the latest version?
- [X] Are you reporting to the correct repository?
- [X ] Did you perform a cursory search?
Description
System.Reflection.TargetInvocationException: 'Failed to load language 'IronPython 3.4.0b1': No data is available for encoding 850. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.'
Steps to Reproduce
-
Console app either NET6 or NET CORE 3.1
-
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); //UNSUCCESSFUL TRY adding this.
-
The code: public class Program { static void Main(string[] args) {
var eng = IronPython.Hosting.Python.CreateEngine(); var scope = eng.CreateScope(); eng.Execute(@" def greetings(name): return 'Hello ' + name.title() + '!' ", scope); dynamic greetings = scope.GetVariable("greetings"); System.Console.WriteLine(greetings("world")); }}
Expected behavior:
Shot the greeting in console
Actual behavior:
TargetInvocationException
Versions
IronPython 3.4.0b1
Sounds like you are trying to use the .NET Framework version of the assemblies on .NET 6 (or .NET Core 3.1). This will not work. How are you linking in the IronPython assemblies? You need to use the net6.0 (or netcoreapp3.1) version of the assemblies.
You have also reformatted the example by adding some whitespace at the beginning of the lines. After you resolve the linking problem, the example will still fail. In Python, there are strict rules on indentation of code. The simplest way to fix your test code is by moving def to the beginning of the line.
I referenced the NET6 dll with add reference in project, its a .NET 6 console app with nothing else. Thanks!
UPDATE: I tried in another machine, now the error is other encoding(same project)
'Failed to load language 'IronPython 3.4.0b1': No data is available for encoding 437. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.'
This is exactly the issue you would get when trying to use the .NET Framework version of the assemblies. Can you try changing your program to:
Console.WriteLine(IronPython.Runtime.ClrModule.TargetFramework);
What does this output? You should see .NETCoreApp,Version=v6.0 if you are using the correct assemblies.
In any case, I would suggest using the NuGet package instead of referencing the assemblies directly. Assuming you're using the .NET 6 SDK:
dotnet new consoledotnet add package IronPython -v 3.4.0-beta1- Your project file now looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IronPython" Version="3.4.0-beta1" />
</ItemGroup>
</Project>
- Edit Program.cs to contain the following:
var engine = IronPython.Hosting.Python.CreateEngine();
engine.Execute("print('Hello World!')");
dotnet run- And you should see
Hello World!.
Thanks all i will try and tell you if it worked, sorry , its beeing a busy week.