Skip to content

Unable to find assembly #468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JamesMTSloan opened this issue May 18, 2017 · 6 comments
Closed

Unable to find assembly #468

JamesMTSloan opened this issue May 18, 2017 · 6 comments

Comments

@JamesMTSloan
Copy link

JamesMTSloan commented May 18, 2017

Environment

  • Pythonnet version: 2.3.0
  • Python version: 3.5 (both installed using Anaconda) 64-bit
  • Operating System: Windows 7 64-bit

Details

I am trying to load a .NET assembly DLL using pythonnet. This has worked fine for other DLLs (.NET 4) but for one in particular I am having issues. This is an assembly provided by the Sapera SDK made by DALSA. I don't know what .NET version this was made using, presumably 4 but I don't know how to check. The docs for it say NET 3.5+ required.

Using the VS dependency checker I have determined that all the required DLLs are on the path (although I had to move MSVCR80.dll and MSVCP80.dll into System32 from an odd location). DependencyWalker shows a couple more that may be missing and suggests that the DLL is 64-bit.

The dependencies that I get from VS are:
corapi.dll, WINMM.dll, KERNEL32.dll, USER32.dll, GDI32.dll, MSVCR80.dll, MSVCP80.dll, msvcm80.dll, mscoree.dll

The following code produces a Traceback:

import clr
import sys

assemblydir = "C:/Program Files/Teledyne DALSA/Sapera/Components/NET/Bin"
assemblyname = "DALSA.SaperaLT.SapClassBasic"

sys.path.insert(0, "C:/Windows/System32")
sys.path.insert(0, assemblydir)
clr.AddReference(assemblyname)
Traceback (most recent call last):
  File "netdlltest.py", line 9, in <module>
    clr.AddReference(assemblyname)
System.IO.FileNotFoundException: Unable to find assembly 'DALSA.SaperaLT.SapClassBasic'.
   at Python.Runtime.CLRModule.AddReference(String name)

Is there something I am overlooking? I imagine it can actually find it but is failing to load it for some reason. Thanks for any help you can provide.

@den-run-ai
Copy link
Contributor

@JamesMTSloan please follow the advises for troubleshooting in this resolved issue:

#466

@JamesMTSloan
Copy link
Author

I updated to .NET 4.7 and the error persisted. The output of fuslogvw and ILSPY suggest to me that the DLL was built using .NET 2.0. Does pythonnet require DLLs to be 3.5+?

Outputs:

// C:\Program Files\Teledyne DALSA\Sapera\Components\NET\Bin\DALSA.SaperaLT.SapClassBasic.dll
// DALSA.SaperaLT.SapClassBasic, Version=8.20.0.1718, Culture=neutral, PublicKeyToken=4d8604101dcb6b58

// Global type: <Module>
// Architecture: x64
// This assembly contains unmanaged code.
// Runtime: .NET 2.0

using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Permissions;

[assembly: AssemblyVersion("8.20.0.1718")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyCompany("Teledyne DALSA")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCopyright("Copyright (c) Teledyne DALSA Inc. 2007-2016")]
[assembly: AssemblyDescription("Sapera LT .NET Classes")]
[assembly: AssemblyProduct("Sapera LT")]
[assembly: AssemblyTitle("DALSA.SaperaLT.SapClassBasic")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: SecurityPermission(8, SkipVerification = true)]
[assembly: SecurityPermission(8, UnmanagedCode = true)]
*** Assembly Binder Log Entry  (18/05/2017 @ 16:43:26) ***

The operation failed.
Bind result: hr = 0x80004005. Unspecified error

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\ProgramData\Anaconda3\python.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: Where-ref bind. Location = C:\Program Files\Teledyne DALSA\Sapera\Components\NET\Bin\DALSA.SaperaLT.SapClassBasic.dll
LOG: Appbase = file:///C:/ProgramData/Anaconda3/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = python.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: No application configuration file found.
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Attempting download of new URL file:///C:/Program Files/Teledyne DALSA/Sapera/Components/NET/Bin/DALSA.SaperaLT.SapClassBasic.dll.
LOG: Assembly download was successful. Attempting setup of file: C:\Program Files\Teledyne DALSA\Sapera\Components\NET\Bin\DALSA.SaperaLT.SapClassBasic.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: DALSA.SaperaLT.SapClassBasic, Version=8.20.0.1718, Culture=neutral, PublicKeyToken=4d8604101dcb6b58
LOG: Re-apply policy for where-ref bind.
LOG: Post-policy reference: DALSA.SaperaLT.SapClassBasic, Version=8.20.0.1718, Culture=neutral, PublicKeyToken=4d8604101dcb6b58
LOG: GAC Lookup was unsuccessful.
LOG: Where-ref bind Codebase does not match what is found in default context. Keep the result in LoadFrom context.
LOG: Binding succeeds. Returns assembly from C:\Program Files\Teledyne DALSA\Sapera\Components\NET\Bin\DALSA.SaperaLT.SapClassBasic.dll.
LOG: Assembly is loaded in LoadFrom load context.
ERR: Rejecting IJW module built against v2.0.50727 because it could be loaded into another runtime in this process.

Cheers

@den-run-ai
Copy link
Contributor

@JamesMTSloan this assembly contains unmanaged code (e.g. C++/CLI), hence cannot redirect at runtime from CLR2 to CLR4. It has to be recompiled to target .NET 4.0+. pythonnet does not work in CLR2 due to usage of dynamic and hashset.

@JamesMTSloan
Copy link
Author

Thanks very much for your help. It is a third party DLL but perhaps I can make an enquiry anyway. Thanks again.

@den-run-ai
Copy link
Contributor

Closing, since pythonnet cannot really do anything here

@chaojian-zhang
Copy link

Related: #2588

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants