使用工具:Pythonnet, target.dll
Dllcode:
namespace TestNS
{
public class Test
{
public int Add(int a, int b)
{
return a + b;
}
}
}
Python Examples:
确保dll已经在项目的搜索路径中,若不在,使用sys.path添加
clr.AddReference(“target”)
from TestNS import Test
test = Test()
test.Add()
调试方法:
dll_ref = System.Reflection.Assembly.LoadFile(dll_path)
print(dll_ref.FullName)
print(dll_ref.Location)
for i in range(len(dll_ref.DefinedTypes)):
print(dll_ref.DefinedTypes[i])
上述代码可查看dll所包含内容及导入异常代码
.Net异常原因分析:
https://airbrake.io/blog/dotnet-exception-handling/system-badimageformatexception
Pythonnet使用指南链接
/pythonnet/pythonnet/wiki