Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Possible causes for ModuleNotFoundError with .NET Framework DLL. #2331

Closed
draustin opened this issue Feb 28, 2024 · 0 comments
Closed

Possible causes for ModuleNotFoundError with .NET Framework DLL. #2331

draustin opened this issue Feb 28, 2024 · 0 comments

Comments

@draustin
Copy link

Environment

  • Pythonnet version: 3.03
  • Python version: 3.11.7
  • Operating System: Windows 11 Pro
  • .NET Runtime: DotNetVersions reports

Currently installed "classic" .NET Versions in the system:
4.0.0.0
4.8.09032

Details

In Python, I am trying to use a .NET DLL supplied by a hardware vendor ("Suragus"). The DLL targets .NET Framework 4.6.1. I can add it as a reference, see its references, and load it, but I get a ModuleNotFoundError when I import a namespace that it provides.

I am investigating three possible causes of the issue.

  1. Does Pythonnet support the use of DLLs targeting .NET Framework 4.6.1? I saw this closed issue, but am not sure whether it refers to the target version of a .NET DLL, or the runtime, or both. I cannot find a definitive statement of the Pythonnet's compatibility with the target version of a .NET DLL.
  2. My lack of a runtimeconfig.json file. The vendor has not supplied one. As above, I have .NET Framework 4.0 and 4.8 on my system. Could Pythonnet be selecting 4.0? The output from get_runtime_info does not say. The vendor states that .NET Framework 4.6.1 or above is required.
  3. A missing referenced DLL. The DLL that I am trying to load references a DLL that is not present. The vendor assures me that this DLL is not necessary, but maybe it presents a problem for Pythonnet? The assembly can be added and loaded (see code below).

I realize that this is partly a support request, but it also relates to the completeness of documentation and specificity of error messages, which is why I'm posting it here.

Here is the code that I am using to investigate. I have described the output in comments, but cannot share it in full.

import pythonnet as pn
import clr

print(pn.get_runtime_info())
#Runtime: .NET Framework
#=============
# Version:      <undefined>
# Initialized:  True
#  Shut down:    False
# Properties:
#   domain =
#   config_file = None
#

# I can add it as a reference. The printed description makes sense.
sdk = clr.AddReference("Suragus.Ec.Sdk")
print("SDK:", sdk)

# I can get its referenced assemblies. These are consistent with ILSpy.
from System.Reflection import Assembly
sdk_references = Assembly.GetReferencedAssemblies(sdk)
print("Referenced Assemblies:")
for item in sdk_references:
    print(item)

# Most the the referenced assemblies are printed here, but some are missing. The vendor asserts that they are not necessary.
print("ListAssemblies:")
for item in clr.ListAssemblies(True):
    print(item)

loaded_sdk = Assembly.Load("Suragus.Ec.Sdk")
print("Loaded:", loaded_sdk)

# But importing a namespace raises: "ModuleNotFoundError: No module named 'Suragus'".
import Suragus
@pythonnet pythonnet locked and limited conversation to collaborators Feb 28, 2024
@filmor filmor converted this issue into discussion #2332 Feb 28, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant