Skip to content

Python.Runtime fails on .NET 4.5 and up #3

Closed

Description

@dmitry-a-morozov

Currently library fails on .NET 4.5. I know that 4.5 is not technically supported but the issue very painful because .NET 4.5 is update in place which overrides CLR. So, having it installed I don't really have an option to run it on ver 4.
When I try to run an application that uses Python for .NET i get exception

System.ArgumentNullException was unhandled
HResult=-2147467261
Message=Value cannot be null.
Parameter name: key
Source=mscorlib
ParamName=key
StackTrace:
at System.Collections.Generic.Dictionary2.FindEntry(TKey key) at System.Collections.Generic.Dictionary2.TryGetValue(TKey key, TValue& value)
at Python.Runtime.GenericUtil.Register(Type t) in D:\Users\Barton\Documents\Visual Studio 2010\Projects\PySharp\trunk\pythonnet\src\runtime\genericutil.cs:line 41
at Python.Runtime.AssemblyManager.ScanAssembly(Assembly assembly) in D:\Users\Barton\Documents\Visual Studio 2010\Projects\PySharp\trunk\pythonnet\src\runtime\assemblymanager.cs:line 266
at Python.Runtime.AssemblyManager.Initialize() in D:\Users\Barton\Documents\Visual Studio 2010\Projects\PySharp\trunk\pythonnet\src\runtime\assemblymanager.cs:line 60
at Python.Runtime.Runtime.Initialize() in D:\Users\Barton\Documents\Visual Studio 2010\Projects\PySharp\trunk\pythonnet\src\runtime\runtime.cs:line 166
at Python.Runtime.PythonEngine.Initialize() in D:\Users\Barton\Documents\Visual Studio 2010\Projects\PySharp\trunk\pythonnet\src\runtime\pythonengine.cs:line 118
at Program.Program.main(String[] _arg1) in C:\Users\mitekm\Documents\Visual Studio 2013\Projects\TryPythonForNet\TryPythonForNet\Program.fs:line 54
InnerException:

I did some extra investigation. What happens is that this line of code fails

https://github.com/pythonnet/pythonnet/blob/develop/pythonnet/src/runtime/genericutil.cs#L41

because Namespace property is null on generic type EmptyArray`1 introduced in .NET 4.5. This type located in root namespace therefore Namespace property value is null.
I made quick fix on
https://github.com/pythonnet/pythonnet/blob/develop/pythonnet/src/runtime/assemblymanager.cs#L286

to replace
if (t.IsGenericTypeDefinition) {
GenericUtil.Register(t);
}

with
if (t.IsGenericTypeDefinition && t.IsPublic) {
GenericUtil.Register(t);
}
Honestly, I don't understand why the Python.Runtime process non-public type.

It worked on .NET 4 because this type EmptyArray'1 didn't exist there. As a matter of fact there were no generic types in root namespace.

Do you plan to start taking pull requests soon?

Thanks, Dmitry

Activity

  1. davidanthoff commented on Feb 1, 2014

    @davidanthoff
    Contributor

    I just got the ok from the original maintainers that this github repo is now the new official home for this project. That means we are taking fixes etc. Mostly we need help, though. I started this push to github because I need a working version of this project, but I am myself not very familiar with the codebase. So, any help from your side would be greatly appreciated!

  2. dmitry-a-morozov commented on Feb 1, 2014

    @dmitry-a-morozov
    Author

    Great news! I'm in similar position. I need working version of this project for https://github.com/fsprojects/FSharp.Interop.PythonProvider. And I'm not familiar with code base at all. I will try to help us much as I can. I'm little swamped with my open source work.

  3. added this to the milestone on Feb 11, 2014
  4. added a commit that references this issue on Oct 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions