Skip to content

Failed to load language 'IronPython 2.7.11': Value cannot be null. (Parameter 'path1') when producing single file #762

Closed
@newbienewbie

Description

@newbienewbie

Prerequisites

  • Are you running the latest version?
  • Are you reporting to the correct repository?
  • Did you perform a cursory search?

Description

get an error of "Failed to load language 'IronPython 2.7.11': Value cannot be null. (Parameter 'path1')" when publishing a .net5.0 project with the "Produce Single File" option setting as True.

Steps to Reproduce

  1. create a c# project using .NET 5 which targets net5.0
  2. invoke Python as below:
    class Program
    {
        static void Main(string[] args)
        {
            RunScript();
        }

        static ScriptEngine scriptEngine = null;
        static ScriptScope scriptScope = null;

        static void RunScript()
        {
            if (scriptEngine is null)
            {
                scriptEngine = Python.CreateEngine();
                scriptScope = scriptEngine.CreateScope();
                scriptScope.SetVariable("Hello","World");
            }

            var source = scriptEngine.CreateScriptSourceFromString("print Hello");
            var code = source.Compile();
            code.Execute(scriptScope);
        }
    }
  1. publish the project by
dotnet publish -c Release -r win-x64  --self-contained true -p:PublishSingleFile=true

run the published exe
Expected behavior: The above prints "World" succeessfully.

Actual behavior: I get an error as below

...\bin\Release\net5.0\win-x64\publish> .\TestIronPython.exe
Unhandled exception. System.Reflection.TargetInvocationException: Failed to load language 'IronPython 2.7.11': Value cannot be null. (Parameter 'path1')
 ---> System.ArgumentNullException: Value cannot be null. (Parameter 'path1')
   at System.IO.Path.Combine(String path1, String path2)
   at IronPython.Runtime.PythonContext..ctor(ScriptDomainManager manager, IDictionary`2 options)
   --- 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()
   at TestIronPython.Program.RunScript()
   at TestIronPython.Program.Main(String[] args)

Versions

You can get this information from executing ipy -V.

I'm not sure how to execute this command. I'm not invoking C# from python but instead invoking Python Script within a C# project.

  • OS Version: Win10.0.19041:
  • dotnet: 5.0.101

I'm using IronPython of 2.7.11

    <PackageReference Include="IronPython" Version="2.7.11" />

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions