I'm setting up a Jupyter Notebook within which a C# DLL is called. This works fine when calling a single self contained DLL, but fails when the DLL depends on another C# DLL.
The call to the DLL is done using ctypes and the UnmanagedExports as explained here: https://stackoverflow.com/a/29854281/11588296
The entry DLL's source code is:
using RGiesecke.DllExport;
using System.Runtime.InteropServices;
namespace SimpleCSharpPython
{
public class Test
{
[DllExport("addDirect", CallingConvention = CallingConvention.Cdecl)]
public static int TestExport1(int left, int right)
{
return left + right;
}
[DllExport("addExtern", CallingConvention = CallingConvention.Cdecl)]
public static int TestExport2(int left, int right)
{
return UnderlyingLib.UnderlyingFunc.TestExternExport(left, right);
}
}
}
The underlying DLL is:
namespace UnderlyingLib
{
public class UnderlyingFunc
{
public static int TestExternExport(int left, int right)
{
return left + right;
}
}
}
Finally, the Jupyter Notebook is:
import ctypes
a= ctypes.cdll.LoadLibrary("SimpleCSharpPython.dll")
b= ctypes.cdll.LoadLibrary("UnderlyingLib.dll")
a.addDirect(3, 5)
a.addExtern(3, 4)
The output of the first call (a.addDirect(3, 5)) is 8, as expected. The output of the second call is the following error
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-4-c4df87cc7b32> in <module>
----> 1 a.addExtern(3,4)
OSError: [WinError -532462766] Windows Error 0xe0434352
Note the notebook and the 2 DLLs are in the same folder, and the 2 DLLs run fine when called by a C# executable in Visual Studio. I've tried multiple build, path, ctypes calls, but no luck.
Any idea would be greatly appreciated. Let me know if any additional information is required.
I am not an expert but i will try this:
User contributions licensed under CC BY-SA 3.0