pythonnet / pythonnet/clr-loader

netfx loader with LOAD_LIBRARY_SEARCH_USER_DIRS

Open
#77 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
42
Forks
32
Avg merge
14h 1m
Merged PRs (30d)
1

Description

If the win32 API SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_USER_DIRS) is used, the default clr_loader doesn't work.

import ctypes
from ctypes import wintypes

dll = ctypes.CDLL("Kernel32.dll")
dll.SetDefaultDllDirectories.argtypes=[wintypes.DWORD]
LOAD_LIBRARY_SEARCH_USER_DIRS = 0x00000400
dll.SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_USER_DIRS)
import clr # <---- crash

This search mode is documented here

It is used in the python distribution from the windows store (although I don't know if this issue is reproducible there) as well as some embedders of Python.

I tried the following as a workaround:
import os
os.add_dll_directory(r"C:\Windows\Microsoft.NET\Framework64\v4.0.30319")
os.add_dll_directory(r"C:\path\to\python\env\site-packages\clr_loader\ffi\dlls\amd64")

And it didn't work.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Python snippet that calls SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_USER_DIRS) before importing clr. Inspect the clr_loader DLL-loading path and its ffi/dlls/amd64 directory, then verify that importing clr works under this Windows search mode without relying on the reported workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.