Maroder1 / Openness_examples_python

30 stars 8 forks source link

clr FileLoadException HRESULT: 0x80131047 #3

Open silvestrid opened 3 years ago

silvestrid commented 3 years ago

Hi,

I am trying to load the .dll from 'C:\Program Files\Siemens\Automation\Portal V16\PublicAPI\V16\Siemens.Engineering.dll' (where the .dll is located) but clr gives this error: FileLoadException: HRESULT: 0x80131047

in System.Reflection.AssemblyName.nInit(RuntimeAssembly& assembly, Boolean forIntrospection, Boolean raiseResolveEvent) in System.Reflection.RuntimeAssembly.CreateAssemblyName(String assemblyString, Boolean forIntrospection, RuntimeAssembly& assemblyFromResolveEvent) in System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) in System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) in System.Reflection.Assembly.Load(String assemblyString) in Python.Runtime.AssemblyManager.LoadAssembly(String name) in Python.Runtime.CLRModule.AddReference(String name)

Do you have idea of what is the problem?

I already add my username to "Siemens TIA Openness" group.

silvestrid commented 3 years ago

with: clr.AddReference('C:\Program Files\Siemens\Automation\Portal V16\PublicAPI\V16\Siemens.Engineering') it works!

I removed the ".dll" suffix and it works now. Thank you for your work

Maroder1 commented 3 years ago

Hi thanks for the note. Not sure why that caused problems for you (and works for me)... Could be a different version of some module? Either way good to be aware of!

silvestrid commented 3 years ago

I'm using Python 3.9.2 and this is the version of pythonnet: git+https://github.com/pythonnet/pythonnet@6f1219f7d3f6a53c9ae932e51cb2c15aad54fb54 (master at 02/23/21)..

maybe could be useful for someone novice with pythonet like me.

Maroder1 commented 3 years ago

Did the following test: Created a new Conda env with python 3.9 and did a pip install pythonnet inside the env.

Still works for me so I'm having a hard time to recreate and troubleshoot your issue. Are you testing inside an environment?

Can you test the following and post result? (change file location to match yours):

from clr import System from System import Reflection full_filename = r'C:\Program Files\Siemens\Automation\Portal V16\PublicAPI\V16\Siemens.Engineering.dll' Reflection.Assembly.LoadFile(full_filename)

Above works for me with the ".dll", but not without.
When using the clr.AddReference it works both with and without.