Skip to content

C# initialize fails if a class derived from IEnumerable and IEnumerator is in global namespace #1601

@mfrankeTT

Description

@mfrankeTT

Environment

  • Pythonnet version: master build from 21/10/14
  • Python version: tested with WinPython 3.6.6.2, 3.7.0, 3.7.1, 3.8.9
  • Operating System: Windows10
  • .NET Runtime: v4.7.1

Details

  • Describe what you were trying to get done.

I tried to integrate a local python (WinPython) into a Unity application via pythonnet. While this worked for an easy demo project, initialization constantly failed for our production setup:

Creating a VS 2017/2019 project with the code in global namespace triggers the error (no need to actually use the class somewhere). Commenting out the Test123 class or putting it in a namespace solves the problem.

    public class Test123 : IEnumerator, IEnumerable
    {
        object IEnumerator.Current
        {
            get { return null; }
        }

        public IEnumerator GetEnumerator()
        {
            return this;
        }

        public bool MoveNext()
        {
            return true;
        }

        public void Reset()
        { }
    }
    
     class Program
    {
        static void Main(string[] args)
        {
            Runtime.PythonDLL = @".\..\..\..\..\..\..\winpython\WPy64-3771\python-3.7.7.amd64\python37.dll";

            var pythonPath = @".\..\..\..\..\..\..\winpython\WPy64-3771\python-3.7.7.amd64";
            Environment.SetEnvironmentVariable("PATH", $@"{pythonPath};" + Environment.GetEnvironmentVariable("PATH"));
            Environment.SetEnvironmentVariable("PYTHONHOME", pythonPath);
            Environment.SetEnvironmentVariable("PYTHONPATH ", $@"{pythonPath}\Lib");

            PythonEngine.Initialize();
        }
    }
  • If there was a crash, please include the traceback here.
nvalidOperationException: ValueFactory attempted to access the Value property of this instance.
System.Lazy`1[T].CreateValue () (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Lazy`1[T].LazyInitValue () (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Lazy`1[T].get_Value () (at <437ba245d8404784b9fbab9b439ac908>:0)
Python.Runtime.Runtime.get_InteropModule () (at C:/dev/projects/pynet/pythonnet/src/runtime/runtime.cs:574)
Python.Runtime.PythonException.TryDecodePyErr (Python.Runtime.BorrowedReference typeRef, Python.Runtime.BorrowedReference valRef, Python.Runtime.BorrowedReference tbRef) (at C:/dev/projects/pynet/pythonnet/src/runtime/pythonexception.cs:205)
Python.Runtime.PythonException.FetchCurrentOrNull (System.Runtime.ExceptionServices.ExceptionDispatchInfo& dispatchInfo) (at C:/dev/projects/pynet/pythonnet/src/runtime/pythonexception.cs:105)
Python.Runtime.PythonException.ThrowLastAsClrException () (at C:/dev/projects/pynet/pythonnet/src/runtime/pythonexception.cs:44)
Python.Runtime.PythonException.ThrowIfIsNull (Python.Runtime.BorrowedReference ob) (at C:/dev/projects/pynet/pythonnet/src/runtime/pythonexception.cs:429)
Python.Runtime.PyModule.Import (System.String name) (at C:/dev/projects/pynet/pythonnet/src/runtime/module.cs:75)
Python.Runtime.Runtime+<>c__DisplayClass31_0.<GetModuleLazy>b__0 () (at C:/dev/projects/pynet/pythonnet/src/runtime/runtime.cs:402)
System.Lazy`1[T].CreateValue () (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Lazy`1[T].LazyInitValue () (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Lazy`1[T].get_Value () (at <437ba245d8404784b9fbab9b439ac908>:0)
Python.Runtime.Runtime.get_InteropModule () (at C:/dev/projects/pynet/pythonnet/src/runtime/runtime.cs:574)
Python.Runtime.PythonException.TryDecodePyErr (Python.Runtime.BorrowedReference typeRef, Python.Runtime.BorrowedReference valRef, Python.Runtime.BorrowedReference tbRef) (at C:/dev/projects/pynet/pythonnet/src/runtime/pythonexception.cs:205)
Python.Runtime.PythonException.FetchCurrentOrNull (System.Runtime.ExceptionServices.ExceptionDispatchInfo& dispatchInfo) (at C:/dev/projects/pynet/pythonnet/src/runtime/pythonexception.cs:105)
Python.Runtime.PythonException.ThrowLastAsClrException () (at C:/dev/projects/pynet/pythonnet/src/runtime/pythonexception.cs:44)
Python.Runtime.PythonException.ThrowIfIsNull (Python.Runtime.BorrowedReference ob) (at C:/dev/projects/pynet/pythonnet/src/runtime/pythonexception.cs:429)
Python.Runtime.PyModule.Import (System.String name) (at C:/dev/projects/pynet/pythonnet/src/runtime/module.cs:75)
Python.Runtime.Py.Import (System.String name) (at C:/dev/projects/pynet/pythonnet/src/runtime/pythonengine.cs:776)
Python.Runtime.InteropConfiguration+<>c.<MakeDefault>b__3_0 () (at C:/dev/projects/pynet/pythonnet/src/runtime/InteropConfiguration.cs:23)
System.Lazy`1[T].CreateValue () (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Lazy`1[T].LazyInitValue () (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Lazy`1[T].get_Value () (at <437ba245d8404784b9fbab9b439ac908>:0)
Python.Runtime.Mixins.CollectionMixinsProvider.get_Mixins () (at C:/dev/projects/pynet/pythonnet/src/runtime/Mixins/CollectionMixinsProvider.cs:15)
Python.Runtime.Mixins.CollectionMixinsProvider.GetBaseTypes (System.Type type, System.Collections.Generic.IList`1[T] existingBases) (at C:/dev/projects/pynet/pythonnet/src/runtime/Mixins/CollectionMixinsProvider.cs:57)
Python.Runtime.PythonBaseTypeProviderGroup.GetBaseTypes (System.Type type, System.Collections.Generic.IList`1[T] existingBases) (at C:/dev/projects/pynet/pythonnet/src/runtime/PythonBaseTypeProviderGroup.cs:18)
Python.Runtime.TypeManager.GetBaseTypeTuple (System.Type clrType) (at C:/dev/projects/pynet/pythonnet/src/runtime/typemanager.cs:443)
Python.Runtime.TypeManager.InitializeClass (System.Type clrType, Python.Runtime.PyType pyType) (at C:/dev/projects/pynet/pythonnet/src/runtime/typemanager.cs:229)
Python.Runtime.TypeManager.GetOrCreateClass (System.Type type) (at C:/dev/projects/pynet/pythonnet/src/runtime/typemanager.cs:158)
Python.Runtime.ClassManager.InitPyType (System.Type type, Python.Runtime.ClassBase impl) (at C:/dev/projects/pynet/pythonnet/src/runtime/classmanager.cs:263)
Python.Runtime.ClassManager.GetClass (System.Type type) (at C:/dev/projects/pynet/pythonnet/src/runtime/classmanager.cs:195)
Python.Runtime.ModuleObject.GetAttribute (System.String name, System.Boolean guess) (at C:/dev/projects/pynet/pythonnet/src/runtime/moduleobject.cs:120)
Python.Runtime.ModuleObject.LoadNames () (at C:/dev/projects/pynet/pythonnet/src/runtime/moduleobject.cs:191)
Python.Runtime.ImportHook.UpdateCLRModuleDict () (at C:/dev/projects/pynet/pythonnet/src/runtime/importhook.cs:218)
Python.Runtime.ImportHook.GetCLRModule () (at C:/dev/projects/pynet/pythonnet/src/runtime/importhook.cs:230)
Python.Runtime.PythonEngine.Initialize (System.Collections.Generic.IEnumerable`1[T] args, System.Boolean setSysArgv, System.Boolean initSigs, Python.Runtime.ShutdownMode mode) (at C:/dev/projects/pynet/pythonnet/src/runtime/pythonengine.cs:223)
Python.Runtime.PythonEngine.Initialize (System.Boolean setSysArgv, System.Boolean initSigs, Python.Runtime.ShutdownMode mode) (at C:/dev/projects/pynet/pythonnet/src/runtime/pythonengine.cs:184)
Python.Runtime.PythonEngine.Initialize () (at C:/dev/projects/pynet/pythonnet/src/runtime/pythonengine.cs:179)
ve.vet.Python.PythonIntegration..ctor () (at Assets/Source/ve.vet.Python/PythonIntegration.cs:36)
ve.vet.Python.PythonIntegrationExample..ctor () (at Assets/Source/ve.vet.Python/examples/PythonIntegrationExample.cs:25)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy