'TypeLoadException in Python while using Python.Net

I am using 2 .net class libraries in the Python using Python.Net

Wanted to pass class object as parameter in a method call

PT.cs

using System;

namespace Point
{
    public class PT
    {
        public int x { get; set; }
        public int y { get; set; }

        public PT()
        {
            x = 0;y = 0;
        }

        public PT(int X,int Y)
        {
            x = X;y = Y;
        }
    }
}

Cal.cs

using System;
using Point;

namespace Calculator
{
    public class Cal
    {
        public double X { get; set; }
        public double Y { get; set; }
        public Cal()
        {
            X = 0.0;
            Y = 0.0;
        }
        public Cal(double x, double y)
        {
            X = x;
            Y = y;
        }
        public static double  Add(double x,double y)
        {
            return x + y;
        }

        public double Add()
        {
            return X + Y;
        }

        public PT AddPoints(PT p1, PT p2)
        {
            int x = Convert.ToInt32(Add(p1.x, p2.x));
            int y = Convert.ToInt32(Add(p1.y, p2.y));

            return new PT(x,y);
        }
    }
}

Using Jupyter Notebook

import sys
import clr
sys.path.append(r"/Users/user/Projects/CalculatorCheck/Calculator/bin/Debug/net5.0/")
clr.AddReference("Calculator")
clr.AddReference("Point")

from Calculator import Cal
from Point import PT

p1=PT(10,10)
p2=PT(20,20)

p3=obj.AddPoints(p1,p2)

Getting error

TypeLoadException Traceback (most recent call last) /var/folders/n7/k0yrxn111wx0wccws6chllth0000gn/T/ipykernel_5171/710681155.py in ----> 1 p3=obj.AddPoints(p1,p2)

TypeLoadException: Could not resolve type with token 01000011 from typeref (expected class 'System.Convert' in assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&) at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in :0



Solution 1:[1]

You are probably using Python.NET 2.5, which does not support .NET 5.0.

You need to install Python.NET 3.0 or later, and you need to configure it to use the correct .NET runtime (by default Mono is used, which also does not support .NET 5).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 LOST