Search code examples
pythonc#.netironpython

IronPython script using C# Reference throws ArgumentTypeException expected got same value


I started few weeks ago a project where I'm using C# References in IronPython. I have been trying a lot of stuff and everything was working so far. Now it got a bit complicated because my python scripter throws the following exception:

Traceback (most recent call last):
  File "C:\Users\ABC\File.py", line 28, in main
    Method(ParameterValue)
TypeError: expected ParameterValue, got ParameterValue

So it is completely the same type what it gets, I also checked it with the isinstance() function. Some people on the internet are telling the path to the references may be the problem but I'm using this style which should be okay:

script_dir = os.path.dirname(__file__)

clr.AddReferenceToFileAndPath(os.path.join(script_dir,'XXXX.dll'))

Thank you guys in advance, I hope there is someone who could give me tips. I'd really appreciate any help.


Solution

  • After using clr.AddReference() I was able to solve the problem. My problem was that I got a duplicate of the paramete I wanted to pass by using AddReferenceToFileAndPath().

    It adds the reference and copies the reference to sys.path, which caused the problem.