System.BadImageFormatException while running pyHamilton

I don’t know why I’m getting this error while trying to run a pyHamilton script.

Traceback (most recent call last):
  File "C:\Users\isaac\.pyenv\pyenv-win\versions\3.8.1\lib\multiprocessing\process.py", line 315, in _bootstrap
    self.run()
  File "C:\Users\isaac\.pyenv\pyenv-win\versions\3.8.1\lib\multiprocessing\process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\isaac\.pyenv\pyenv-win\versions\3.8.1\lib\site-packages\pyhamilton\interface.py", line 205, in run_hamilton_process
    clr.AddReference(os.path.join(OEM_STAR_PATH, 'RunHSLExecutor'))
System.BadImageFormatException: Não foi possível carregar arquivo ou assembly 'file:///C:\Users\isaac\.pyenv\pyenv-win\versions\3.8.1\lib\site-packages\pyhamilton\star-oem\RunHSLExecutor.dll' ou uma de suas dependências. Foi feita uma tentativa de se carregar um programa com um formato incorreto.
Nome do arquivo: 'file:///C:\Users\isaac\.pyenv\pyenv-win\versions\3.8.1\lib\site-packages\pyhamilton\star-oem\RunHSLExecutor.dll'
   em System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   em System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   em System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
   em System.Reflection.Assembly.LoadFrom(String assemblyFile)
   em Python.Runtime.AssemblyManager.LoadAssemblyPath(String name)
   em Python.Runtime.CLRModule.AddReference(String name)

I suspect is because I have two files named RunHSLExecutor.dll in the destinated folder.

No, one is a dll.config file.

I think it’s because you are using 64-bit Python. Try running py 3.8-32 script.py (or whatever version of 32-bit Python you have installed).

1 Like

Thanks, Stefan. Now running a 3.8-32 python version I’m having a time-out issue. I don’t know why, because it seems to be connected to the Hamilton, but even if I run only an INITIALIZE command it gets a timeout.

if __name__ == '__main__':
    plate_pos = source_plate.layout_name() + ', ' + source_plate.position_id(0)
    target_pos = target_site.layout_name() + ', ' + target_site.position_id(0)
    with HamiltonInterface(simulate=False) as hammy:
        hammy.wait_on_response(hammy.send_command(INITIALIZE))
Traceback (most recent call last):
  File ".\src\deck.py", line 15, in <module>
    hammy.wait_on_response(hammy.send_command(INITIALIZE))
  File "C:\Users\isaac\.pyenv\pyenv-win\versions\3.8.7-win32\lib\site-packages\pyhamilton\interface.py", line 652, in wait_on_response     
    self.log_and_raise(HamiltonTimeoutError('Timed out after ' + str(timeout) + ' sec while waiting for response id ' + str(id)))
  File "C:\Users\isaac\.pyenv\pyenv-win\versions\3.8.7-win32\lib\site-packages\pyhamilton\interface.py", line 711, in log_and_raise        
    raise err
pyhamilton.oemerr.HamiltonTimeoutError: Timed out after 60 sec while waiting for response id 0x18745070cb67

It looks like a simple timeout issue, you can try running hammy.wait_on_response(hammy.send_command(INITIALIZE), timeout = 300)

I recommend trying to use the project template by running pyhamilton-new-project from the command line to see a more typical script example. See pyhamilton\liquid_handling_wrappers for a list of basic wrapper commands like initialize(ham_int) that has a built-in 300 second timeout.

Are you saying the timeout is happening before running the INITIALIZE command because I’m sending the command without a timeout=300 as parameter?

That seems to be the case, the default timeout is 60 seconds. If your robot has to do a lengthy initialization, the command will fail even though it should have passed.

1 Like

Still getting a timeout.

Traceback (most recent call last):
  File ".\src\deck.py", line 15, in <module>
    hammy.wait_on_response(hammy.send_command(INITIALIZE), timeout = 300)
  File "C:\Users\isaac\.pyenv\pyenv-win\versions\3.8.7-win32\lib\site-packages\pyhamilton\interface.py", line 652, in wait_on_response     
    self.log_and_raise(HamiltonTimeoutError('Timed out after ' + str(timeout) + ' sec while waiting for response id ' + str(id)))
  File "C:\Users\isaac\.pyenv\pyenv-win\versions\3.8.7-win32\lib\site-packages\pyhamilton\interface.py", line 711, in log_and_raise        
    raise err
pyhamilton.oemerr.HamiltonTimeoutError: Timed out after 300 sec while waiting for response id 0x18895141e0cd

Any other possible way to diagnostic why I’m getting this?

Do you already have run control open? If so, close it. Also, try to run in simulation mode (simulate=True)

1 Like

Running on simulate mode, when it runs the first time I get Analyze method - complete. I clicked on Start and it seems to run normally and I get End method - complete. However if I click on Start one more time it get stucked on a loop and I receive:


From Brazilian Portuguese to English: System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Sockets.SocketException: no connection could be made because the target machine actively refused it 127.0.0.1:3221

That error message results if your python interpreter crashes, leaving your Venus session hanging. Do you have time for a call anytime today? Could be faster debugging. I bet theres something small we are overlooking.

I noticed the laboratory computer is actually using Venus TWO. I installed Venus TWO on my computer.

I ran the robot_method.py using Run Control, not on Simulation mode, and it worked perfectly.

I tried to run using pyHamilton and I got:

Process Process-1:
Traceback (most recent call last):
  File "C:\Users\isaac\.pyenv\pyenv-win\versions\3.8.7-win32\lib\site-packages\pyhamilton\interface.py", line 208, in run_hamilton_process
    from RunHSLExecutor import Class1
ModuleNotFoundError: No module named 'RunHSLExecutor'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\isaac\.pyenv\pyenv-win\versions\3.8.7-win32\lib\multiprocessing\process.py", line 315, in _bootstrap
    self.run()
  File "C:\Users\isaac\.pyenv\pyenv-win\versions\3.8.7-win32\lib\multiprocessing\process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\isaac\.pyenv\pyenv-win\versions\3.8.7-win32\lib\site-packages\pyhamilton\interface.py", line 210, in run_hamilton_process
    raise RuntimeError('RunHSLExecutor DLLs successfully located, but an internal '
RuntimeError: RunHSLExecutor DLLs successfully located, but an internal error prevented import as a CLR module. You might be missing the standard Hamilton software suite HSL executables, their DLLs may not be registered with Windows, or they may not be located in the expected system directory.

Any ideas about what I can do regarding this?

PyHamilton doesn’t work currently on Venus 2