使用 DLL 将 DLL (c#) 导入 Python with pythonnet

问题描述

我正在尝试在 python 中使用 DLL 'codessentials.CGM.dll'(您可以在 https://www.nuget.org/packages/codessentials.CGM/https://github.com/twenzel/CGM 中找到它)。

我的目标是将二进制编码的 .cgm 文件转换为明文格式的 .cgm 文件。为此,我使用以下代码

import os,sys,clr

dll_dir = './'
sys.path.append(os.getcwd())
path = r'%s%s' % (dll_dir,'System.Text.Encoding.CodePages')
clr.AddReference(path)
path = r'%s%s' % (dll_dir,'System.Runtime.CompilerServices.Unsafe')
clr.AddReference(path)
path = r'%s%s' % (dll_dir,'codessentials.CGM')
clr.AddReference(path)

from codessentials.CGM import BinaryCgmFile,ClearTextCgmFile

binaryFile = BinaryCgmFile('test.cgm')
cleanTextFile = ClearTextCgmFile(binaryFile)
content = cleanTextFile.GetContent()

导入有效,但是当我尝试使用函数“GetContent”时,代码产生以下错误

Traceback (most recent call last):
  File "C:/Users/llyili/PycharmProjects/test_decode_cgm/main.py",line 16,in <module>
    content = cleanTextFile.GetContent()
System.IO.FileNotFoundException: Impossible de charger le fichier ou l'assembly 'System.Text.Encoding.CodePages,Version=4.1.3.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a' ou une de ses dépendances. Le fichier spécifié est introuvable.
   à codessentials.CGM.Export.DefaultClearTextWriter..ctor(Stream stream)
   à codessentials.CGM.ClearTextCgmFile.WriteFile(Stream stream)
   à codessentials.CGM.ClearTextCgmFile.GetContent()

有什么方法可以找出 DLL 使用的 DLL 导入失败的原因? 我尝试使用 clr 导入 DLL 'System.Text.Encoding.CodePages',但在 Internet 上找不到 4.1.3.0 版本,因此我在下面的代码中导入了 5.0.0.0 版本。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)