1

We have a C# application and we need to provide Python scripting interface. Now it's implemented in a way that:

  • A managed scripting library (compiled as a DLL) does all the core work
  • A C++/CLI wrapper (wraps around the managed library and is compiled as a static library) does all the native-managed data translation
  • A boost extension project (BOOST_PYTHON_MODULE) (compiled as a dynamic library with the extension manually changed to pyd) talks to the C++/CLI wrapper layer.

The problem I have is that every time any python app tries to use the interface, it will complain the core managed assembly cannot be found. I have to place it either in the Python installation directory, or deploy it into the GAC.

I enabled the Windows Fusion logging and saw that it will only probe the assembly in the Python directory, I wonder if there is a way to direct Python to search for the .NET assembly in our application installation directory, or rather, any custom directory?

I tried all approaches in this post but that does not work for me. Any help will be highly appreciated!

PS:

  • We know that there are other python options like IronPython or Python .NET but we need to be backward compatible so a C++ interface is also required.
  • In case you are curious what error I get, here it is:

    Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'ScriptingInterface, Version=1.3.9.0, Culture=neutral, PublicKeyToken=160df4f7a3973cc2' or one of its dependencies. The system cannot find the file specified. at NativeCommunicator.{ctor}(NativeCommunicator* )

Community
  • 1
  • 1
Ethan
  • 11
  • 3

1 Answers1

0

Esentially to fix the problem you have to:

  1. In your python script as a very first line you have to call "init".
  2. "Init" is a function which you add in your .pyd module
  3. In Init method you simply register a hook for resolving assemblies.
  4. In the hook you have a chance to load your assemblies from whatever directory you want.

Link below might have be helpful for you: Loading Mixed-Mode C++/CLI .dll (and dependencies) dynamically from unmanaged c++

Community
  • 1
  • 1