如何在IronPython中使用C#dll [英] How to use a C# dll in IronPython

查看:101
本文介绍了如何在IronPython中使用C#dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用C#创建了一个dll.如何在IronPython中使用dll.我尝试使用clr.AddReference("yxz.dll")添加dll.但是失败了.我尝试将dll放在IronPython脚本的执行目录中.尝试引用dll时仍然无法声明找不到名称xyz".

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.

推荐答案

import clr    
clr.AddReferenceToFileAndPath(r"C:\Folder\Subfolder\file.dll")

是Jeff在评论中提出的最简单的方法.这也可以:

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

这篇关于如何在IronPython中使用C#dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆