Artem Zhukov Artem Zhukov - 1 month ago 10
Python Question

Adding reference to .net assembly which has dots in name and namespace

I am trying to refer to assembly which has dots in the namespace.

sys.path.append(assemblyPath)

clr.FindAssembly(r"isc.Eng.Hov")
clr.AddReference(r"isc.Eng.Hov")

print 'isc.Eng.Hov' in clr.ListAssemblies(False)

from isc.Eng.Hov import *


Interpreter raises an error:

Traceback (most recent call last):
True
File "/mnt/86f8c6c8-9099-4f32-be68-486a12918546/GoogleDrive/__BACKLOG/RMK_API_LIB/rmkSuppliersDLLswrappers/scr/Hoval/__phex_hoval_dllwrapper.py", line 14, in <module>
from isc.Eng.Hov import *
ImportError: No module named isc.Eng.Hov


How to troubleshoot?

Answer

the solution was to use ILSPY to investigate the DLL and find dependencies (right click recursively for each DLL and click on add dependencies). Then I copied all the dependencies to the same folder where the main DLL was. After that, I ran:

print [a for a in clr.ListAssemblies(False)

and get the list of dependencies which are actually involved:

u'isc.Eng.Hov', u'Microsoft.VisualBasic', u'System.Windows.Forms', u'System.Drawing', u'Accessibility'

and left them in the folder. After doing so the part of code:

sys.path.append(assemblyPath)

clr.AddReference("isc.Eng.Hov")

import isc.Eng.Hov as isk
from isk import *

started work.

Thank you all, especially @denfromufa for help!