Thanks for that: Dependency walker was what I needed to see why it was having issues.
This DLL depends on the .NET Core and Visual C++ Redist (both are installed but it still cant see particular files like: API-MS-WIN-CORE-PROCESSTHREADS-L1-1-3.DLL). Searching for this and other files it is missing, revealed that they are not present on the Server. From what I’ve googled, there could be an issue with the dll linking to files that were moved to other libraries in current OSes. Thank you for your help. Steven From: Mark Visser <ma...@unity3d.com> Sent: Monday, July 11, 2022 8:02 AM To: A list for users and developers of Python.NET <pythonnet@python.org> Subject: [Python.NET] Re: BadImageFormatException or FileNotFoundException- pythonnet and AlphaVSS +1 - in the past I've used https://www.dependencywalker.com/ to figure out the problem. On mac you can use otool -L, and on linux you can use ldd. On Jul 11, 2022, at 9:38 AM, Alex Earl <slide.o....@gmail.com<mailto:slide.o....@gmail.com>> wrote: Sometimes the file not found error occurs because a dependency of the dll can not be found. On Sun, Jul 10, 2022, 20:06 Steven Manross <ste...@manross.net<mailto:ste...@manross.net>> wrote: Howdy all, I am somewhat new to pythonnet and .NET programming, and just joined the mailing list. You have my apologies if I am missing something simple. I am aware that BadImageFormatException suggests that I’m trying to open an x64 DLL on a 32-bit OS or python installation (or vice versa), but neither seem to be the case (that I can tell). Depending on exactly how I call the code, I get a File Not Found or Bad Image Exception. The File Not Found is interesting since the files live in the same directory as a working DLL (AlphaVSS.Common works - built to run on any architecture, AlphaVSS.x64 doesn’t). Specifics: * Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] on win32 * uninstalled Python 3.10 temporarily so I cant get you that detail (sorry) * And the Windows version clearly states it’s Windows Server 2016 x64 I’m doing my testing from ipython. The code below was tested with Python 3.9 x64 (pythonnet 2.5.2 via wheel file) and Python 3.10 x64 (installed pythonnet 3.0.0-dev1 from git master a few days ago) on Windows Server 2016 x64 Evaluation patched for current .NET Frameworks 2022-06 and both produce an error on the following code. AlphaVSS DLLs were generated via powershell/nuget, and I just copied the DLLs from my powershellmodules dir to the “clr_dir” below for testing (documentation suggests you copy the files to the same directory for use). This DLL was created for .NET Framework 4.5 and I’ve installed Framework 4.8 and this Cumulative update: * 2022-06 Cumulative Update for .NET Framework 4.8 for Windows Server 2016 for x64 (KB5014630) This code is eventually intended to manipulate the Volume Shadow Copy Service on Windows. I am aware that there is limited functionality for ShadowCopies from DISKSHADOW and WMI, but wanted to get more functionality from this VSS .NET Library (specifically Shadow Copy Sets), and pythonnet seemed like a great way to implement this code in my favorite scripting language. Here is the documentation for the DLLs (version 2.0.0) if anyone wants that: https://alphavss.alphaleonis.com/api/Alphaleonis.Win32.Vss.html git source: https://github.com/alphaleonis/AlphaVSS I double checked permissions on the DLLs and I have full control as the administrator. UAC is completely turned off on this machine (if it matters). Any suggestions would be appreciated. This is a test system, so I can do just about anything to it including rebuilding it from scratch as it was built specifically for testing this. This is a VM on Hyper-V 2016 (I doubt that matters). Thank you for your time! Steven # ipython dir output In [16]: ! dir "c:\users\administrator\desktop\alphavss" Volume in drive C has no label. Volume Serial Number is 8C70-F8A3 Directory of c:\users\administrator\desktop\alphavss 07/09/2022 03:10 AM <DIR> . 07/09/2022 03:10 AM <DIR> .. 12/03/2019 08:37 PM 69,632 AlphaVSS.Common.dll 12/03/2019 08:37 PM 21,408 AlphaVSS.Common.pdb 12/03/2019 08:37 PM 618,522 AlphaVSS.Common.xml 12/03/2019 08:37 PM 325,120 AlphaVSS.x64.dll 12/03/2019 08:37 PM 271,872 AlphaVSS.x86.dll 12/03/2019 08:29 PM 342,392 Ijwhost.dll 07/09/2022 03:09 AM <DIR> runtimes 07/09/2022 03:10 AM <DIR> win-x64 07/09/2022 03:10 AM <DIR> win-x86 # code import sys import clr import System # from System import Reflection clr_dir = "C:\\Users\\Administrator\\Desktop\\AlphaVSS" if clr_dir not in sys.path: sys.path.append(clr_dir) # common_vss = Reflection.Assembly.LoadFile(f'{clr_dir}\\AlphaVSS.Common.dll') clr.AddReference("AlphaVSS.Common") #pylint:disable=I1101 import Alphaleonis.Win32.Vss as alphavss # clr.AddReference("AlphaVSS.x64") #pylint:disable=I1101 vss = alphavss.VssFactoryProvider.Default # x64_vss = Reflection.Assembly.LoadFile(f'{clr_dir}\\AlphaVSS.x64.dll') # BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) try: factory = vss.GetVssFactory() except System.BadImageFormatException as e: print(f'Bad Image Format: {e}') except OSError as e: # FileNotFoundException: Could not load file or assembly 'AlphaVSS.x64, Version=2.0.0.0, Culture=neutral, PublicKeyToken=959d3993561034e3' or one of its dependencies. The system cannot find the file specified. print(f'File Not Found: {e}') _______________________________________________ PythonNet mailing list -- pythonnet@python.org<mailto:pythonnet@python.org> To unsubscribe send an email to pythonnet-le...@python.org<mailto:pythonnet-le...@python.org> https://mail.python.org/mailman3/lists/pythonnet.python.org/ Member address: slide.o....@gmail.com<mailto:slide.o....@gmail.com> _______________________________________________ PythonNet mailing list -- pythonnet@python.org<mailto:pythonnet@python.org> To unsubscribe send an email to pythonnet-le...@python.org<mailto:pythonnet-le...@python.org> https://mail.python.org/mailman3/lists/pythonnet.python.org/ Member address: ma...@unity3d.com<mailto:ma...@unity3d.com>
_______________________________________________ PythonNet mailing list -- pythonnet@python.org To unsubscribe send an email to pythonnet-le...@python.org https://mail.python.org/mailman3/lists/pythonnet.python.org/ Member address: arch...@mail-archive.com