5

I am trying to add reference to "example_file.dll" using AddReference('example_file') method from clr module:

>>>import clr
>>>clr.AddReference('example_file')

and in result I get:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
System.IO.FileNotFoundException: Unable to find assembly 'example_file'.

at Python.Runtime.CLRModule.AddReference(String name)

All files are located in current working directory and sys.path looks like this:

>>> sys.path
['', 'C:\\Python27\\lib\\site-packages\\pip-1.2.1-py2.7.egg', 'C:\\Python27', 'C
:\\Windows\\system32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib',
'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27\\lib\\
site-packages', 'C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\']

Additionally, in result of:

>>>clr.FindAssembly('example_file')

I get

u'example_file.dll 

The problem arose from day to day. I am confused because it worked fine before - I don't know what could affect on this. I am working with Windows 7 x64, python 2.73 and .Net framework 4

nsconnector
  • 838
  • 6
  • 12
user2010461
  • 51
  • 1
  • 1
  • 2
  • 2
    Have you tried using `clr.AddReferenceToFileAndPath` just to be explicit? – Jeff Hardy Jan 25 '13 at 20:17
  • Is `example_file.dll` compiled against .NET 4? See https://stackoverflow.com/questions/13259617/python-for-net-unable-to-find-assembly-error and http://sourceforge.net/p/pythonnet/bugs/18/ Has anything changed from "before"? – wilee Jan 31 '13 at 18:23
  • 1
    Everyone would probably agree and strongly suggest you moving away from the decade old and outdated Python2.7 and make a quantum leap into reality of Py3.7+. – not2qubit Dec 13 '20 at 15:46
  • AttributeError: module 'clr' has no attribute 'AddReference' – Soerendip Jan 19 '21 at 22:18

1 Answers1

0

Not really enought info here, but there are (at least) 2 things to think about:

  1. That you are not having additional Python related environment variables, already set. For example using a vritual environment or having Python pointing to some other place. Please check if PYTHONHOME and PYTHONPATH are set.
  2. The the DLL you are trying to load have the same bit size as the Python interpreter. I.e . That if you have a 64-bit Python, you may need to load (but not always) a 64-bit DLL.
  3. That the path specification is being read correctly, in your character set.
    sys.path.append(r"C:\Program Files\SomeApi")
not2qubit
  • 14,531
  • 8
  • 95
  • 135