开发者

How do I get python to load .NET .dlls referenced by mixed mode .dlls?

开发者 https://www.devze.com 2023-01-02 18:38 出处:网络
I have a python .pyd that is a mixed mode C++ DLL.The DLL loads fine and loads unmanaged C++ dlls without a problem, but when it tries to load the .NET dlls referenced by the managed C++ dlls it fails

I have a python .pyd that is a mixed mode C++ DLL. The DLL loads fine and loads unmanaged C++ dlls without a problem, but when it tries to load the .NET dlls referenced by the managed C++ dlls it fails with this error message:

Unhandled Exception: System.IO.FileN开发者_StackOverflow社区otFoundException: Could not load file or assembly '...'

Copying these .NET dlls to the directory that pythod_d.exe is contained in allows the .NET libraries to load successfully, but this is not a good long term solution. Is there an environment variable I have to set or some command line option to python_d.exe that will solve my problem?

Note that using IronPython or Python .NET is NOT acceptable.


I think I've resolved the problem. Assembly loading doesn't use the path set by SetDllDirectory(), and it looks like Python calls this function. By registering a delegate for the event AppDomain.AssemblyResolve(), I can catch the name of the dll that failed, append it to the directory obtained from GetDllDirectory(), and then manually load the assembly myself.


I have a little bit experience with this. I believe it's related to the path and init issues as stated in http://effbot.org/pyfaq/is-a-pyd-file-the-same-as-a-dll.htm.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号