How to use a C# dll in IronPython

Prabhu picture Prabhu · Jul 29, 2009 · Viewed 33.1k times · Source

I have created a dll using C#. How do use the dll in IronPython. I have tried to add the dll using clr.AddReference("yxz.dll"). But it fails. I have tried placing the dll in the execution directory of the IronPython script. Still it fails stating that "Name xyz cannot be found" while trying to refer the dll.

Answer

Goswin picture Goswin · Jan 8, 2013
import clr    
clr.AddReferenceToFileAndPath(r"C:\Folder\Subfolder\file.dll")

is the simplest way as proposed by Jeff in the comments. This also works:

import clr
import sys

sys.path.append(r"C:\Folder\Subfolder")  # path of dll
clr.AddReference ("Ipytest.dll") # the dll
import TestNamspace  # import namespace from Ipytest.dll