Skip to content
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

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

Closed
3 tasks done
newbienewbie opened this issue Jan 5, 2021 · 1 comment · Fixed by #764

Comments

@newbienewbie
Copy link

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" />
@slozier
Copy link
Contributor

slozier commented Jan 7, 2021

You are venturing in uncharted territories here. 😄 I'm guessing this is caused by an assembly location which is null when published as single file?

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

Successfully merging a pull request may close this issue.

2 participants