tags:

views:

526

answers:

2

Hi,

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.

+3  A: 

I think it's failing to find the file because it doesn't know where to look for it, see here for a detailed explanation as to how the clr.AddReference...() functions work.

Matt Warren
+1  A: 

The Creating .NET Classes Dynamically from IronPython example, creates an assembly (which is later saved to disk as "DynamicAsm.dll"). It contains a class called "DynamicType", with a single static method called 'test'. This method takes four integers and adds them together.

The nice thing is that this saves "DynamicAsm.dll" to disk. You can then start an IronPython interactive interpreter session and do the following :

>>> import clr
>>> clr.AddReference('DynamicAsm.dll')
>>> import DynamicType
>>> DynamicType.test(2, 3, 4, 5)
14

Note that the example uses the class name in the import statement.

gimel