IronLanguages / ironpython3

Implementation of Python 3.x for .NET Framework that is built on top of the Dynamic Language Runtime.
Apache License 2.0
2.48k stars 287 forks source link

NullReferenceException while creating IronPython engine in referenced project #1778

Open martinmueller4voice opened 7 months ago

martinmueller4voice commented 7 months ago

Description

When calling

var eng = IronPython.Hosting.Python.CreateEngine();

from inside a referenced project, a

NullReferenceException
   at IronPython.Runtime.Importer.ImportReflected(CodeContext context, String name)

will get thrown.

Continue during debugging in VS does work, though, and will create a usable engine nevertheless.

Steps to Reproduce

Create a Windows Forms Application and a library project. Install the IronPython NuGet package in the library project and use the code above to create an engine from within the referenced assembly.

Running the code from within the library throws the NullReferenceException in Importer.ImportReflected().

Trying the exact same steps directly in the main application works without problems.

Version Information

slozier commented 7 months ago

I haven't been able to reproduce the issue. Could you perhaps provide a working example that demonstrates the issue?

martinmueller4voice commented 7 months ago

I've uploaded a test project to GitHub: https://github.com/martinmueller4voice/IronPythonTest Please let me know if you need anything else.

slozier commented 7 months ago

Thanks for the sample. It looks like Visual Studio is trying to be smart and isn't copying IronPython.Modules.dll to the IronPythonTest/bin/Debug folder which is what's causing the NullReferenceException.

martinmueller4voice commented 7 months ago

Ah, of course! The NullRefException disappears if I manually copy over all the missing assemblies (IronPython.Modules.dll, IdonPython.SQLite.dll and IronPython.Wpf.dll) to my output folder manually.

Could it be that the nuspec file is missing those references?