question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ModuleNotFoundError on import of namespace from custom dll

See original GitHub issue

Environment

  • Pythonnet version: 3.0.0.dev1
  • Python version: Python 3.7.3
  • Operating System: Debian (mcr.microsoft.com/dotnet/core/sdk:3.1-buster)
  • .NET Runtime: Microsoft.AspNetCore.App 3.1.18

Details

  • Describe what you were trying to get done. Import a Namespace from a Custom (though not written by me) Assembly. I have confirmed that the namespace I try to import is correct, exists in the DLL, etc.

  • What commands did you run to trigger this issue? If you can provide a I invoke the python script with python3 demo.py

# demo.py
import os
import sys

runtimeConfigPath = r'/usr/share/dotnet/shared/Microsoft.AspNetCore.App/3.1.18/Microsoft.AspNetCore.App.runtimeconfig.json'

from clr_loader import get_coreclr
from pythonnet import set_runtime
rt = get_coreclr(runtimeConfigPath)
set_runtime(rt)
import clr

currentFolder = os.getcwd()
dllFolder = currentFolder + r'/myCustom'
sys.path.append(dllFolder)
clr.AddReference("Someones.Platform.Custom.Client")


from System.Net import ServicePointManager, SecurityProtocolType
from System import Uri, AppDomain, ResolveEventHandler
from System.Reflection import AssemblyName, Assembly

from Someones.Platform.Custom.Client import (
    CustomClientBuilder ...
) # <-- raises ModuleNotFound here
  • If there was a crash, please include the traceback here.
Traceback (most recent call last):
  File "demo.py", line 26, in <module>
    from Someones.Platform.Custom.Client import (
ModuleNotFoundError: No module named 'Someones'

I understand that without the DLL you cannot reproduce this issue. I am not able to provide the DLL as it is proprietary, and further, I am not the author or maintainer. I am able to investigate further, and can build the DLL from source, so what would be helpful to me is some kind of guidance on how to proceed with debugging. I am an experienced python developer, but not deeply versed in .NET/C#.

the guidance for using Fuslogvw.exe is not exactly helpful since I don’t have any windows machine on which to run an exe.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
ssharmamtcommented, Sep 13, 2021

@filmor I am facing similar issue. Could you please help in fixing this? I am using .Net Core 5.0 python 3.8

1reaction
igionacommented, Sep 23, 2021

@filmor

  1. my issues was reproducible also if I compile against netstandard2.1 or net5
  2. on the machine I’m working now, I did a clean install of python (3.9.7-64bits) & newly cloned the repository (master@HEAD) and now I can’t as well reproduce the issue. As soon as I go back on the other machine I’ll gather more information (py version + head) and see weather with everything up-to-date I still have the issue or not
Read more comments on GitHub >

github_iconTop Results From Across the Web

"No module named" error when attempting to importing c# ...
I believe your issue is that you are using the file extension in the import statement. This is what works for me:
Read more >
How to use a C# dll in python project - YouTube
This video will be demonstrating How we can use a C# DLL in our ... pip install package 5:11 Importing dll into python...
Read more >
how the Python import system works
The current module acts as a namespace for the execution of Python code. When Python imports a Python file, it creates a new...
Read more >
importlib — The implementation of import
Changed in version 3.10: Namespace packages created/installed in a different sys.path location after the same namespace was already imported are noticed.
Read more >
Pyqt5 import error. I wanted to compile ...
@eyllanesc I can't install the locate package. Importing matplotlib. QtWidgets import QApplication, QDialog I get the error: ImportError: DLL load failed: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found