pythonnet: ModuleNotFoundError on import of namespace from custom dll

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.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

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

@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

@filmor partially related to that issue, but shouldn’t AddReference fail if there was a problem loading the assembly?