Skip to content

System.TypeInitializationException with pythonnet3.0.0.dev1 calling .NET Core 3.1 libΒ #1430

@Seb394

Description

@Seb394

Environment

  • Pythonnet version: pythonnet3.0.0.dev1 (master branch 10th March 2021)
  • Python version: 3.5.9
  • Operating System: Linux Ubuntu 18.04 LTS
  • .NET Runtime: .NET Core 3.1

Details

  • Describe what you were trying to get done.

    I tried to call methods within a C# lib build on .NET Core 3.1 from python using pythonnet.
    Therefore i downloaded source code from master branch, built and installed pythonnet by myself.

Before i had the same C# lib on .NET Framework4.5 and using pythonnet 2.4.0-dev1 which ran without problems.

Any ideas?
    import clr
    import os
   
    cwd = os.getcwd()

    clr.AddReference(cwd + '/LibraryName.dll')

    # Create library instance failes !
    test = LinuxCanOpenInstrument()

    ....
  • If there was a crash, please include the traceback here.
    /usr/bin/python3.6 /home/dev-flash/projects/IF_Lib_DotNetCore3.1/InstrumentFunctionsLib/bin/Release/netcoreapp3.1/TestDotNetDll.py
System.TypeLoadException: Could not load type of field 'InstrumentFunctions.CanOpenCommunication:m_sendTimer' (16) due to: Could not resolve type with token 01000028 from typeref (expected class 'System.Timers.Timer' in assembly 'System.ComponentModel.TypeConverter, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') assembly:System.ComponentModel.TypeConverter, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a type:System.Timers.Timer member:(null)
  at InstrumentFunctions.LibraryManager..cctor () [0x00020] in <884d81b1dc3b490db2f5701632383726>:0 

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/dev-flash/projects/IF_Lib_DotNetCore3.1/InstrumentFunctionsLib/bin/Release/netcoreapp3.1/TestDotNetDll.py", line 22, in <module>
    test = LinuxCanOpenInstrument()
System.TypeInitializationException: The type initializer for 'InstrumentFunctions.LibraryManager' threw an exception. ---> System.TypeLoadException: Could not load type of field 'InstrumentFunctions.CanOpenCommunication:m_sendTimer' (16) due to: Could not resolve type with token 01000028 from typeref (expected class 'System.Timers.Timer' in assembly 'System.ComponentModel.TypeConverter, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') assembly:System.ComponentModel.TypeConverter, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a type:System.Timers.Timer member:(null)
  at InstrumentFunctions.LibraryManager..cctor () [0x00020] in <884d81b1dc3b490db2f5701632383726>:0 
   --- End of inner exception stack trace ---
  at InstrumentFunctions.LinuxCanOpenInstrument..ctor () [0x0027b] in <884d81b1dc3b490db2f5701632383726>:0 
  at (wrapper managed-to-native) System.Reflection.RuntimeConstructorInfo.InternalInvoke(System.Reflection.RuntimeConstructorInfo,object,object[],System.Exception&)
  at System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) [0x00005] in <533173d24dae460899d2b10975534bb0>:0 

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

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