微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决使用 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 举报,一经查实,本站将立刻删除。