Skip to content

Commit db765ca

Browse files
committed
suggest to set Runtime.PythonDLL when embedding in .NET
1 parent f2dc8f1 commit db765ca

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/runtime/runtime.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -2518,7 +2518,19 @@ static Delegates()
25182518
}
25192519

25202520
static global::System.IntPtr GetFunctionByName(string functionName, global::System.IntPtr libraryHandle)
2521-
=> libraryLoader.GetFunction(libraryHandle, functionName);
2521+
{
2522+
try
2523+
{
2524+
return libraryLoader.GetFunction(libraryHandle, functionName);
2525+
}
2526+
catch (MissingMethodException e) when (libraryHandle == IntPtr.Zero)
2527+
{
2528+
throw new MissingMethodException(
2529+
"Did you forget to set Runtime.PythonDLL?" +
2530+
" See https://github.com/pythonnet/pythonnet#embedding-python-in-net",
2531+
e);
2532+
}
2533+
}
25222534

25232535
internal static delegate* unmanaged[Cdecl]<IntPtr, IntPtr> PyDictProxy_New { get; }
25242536
internal static delegate* unmanaged[Cdecl]<IntPtr, void> Py_IncRef { get; }

0 commit comments

Comments
 (0)