From 0d6cdac21e764af74a89d777bbd0acd29832256d Mon Sep 17 00:00:00 2001 From: Victor Milovanov Date: Sun, 7 Mar 2021 16:35:48 -0800 Subject: [PATCH] suggest to set Runtime.PythonDLL when embedding in .NET --- src/runtime/runtime.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/runtime/runtime.cs b/src/runtime/runtime.cs index a8d861770..b779c6707 100644 --- a/src/runtime/runtime.cs +++ b/src/runtime/runtime.cs @@ -2518,7 +2518,19 @@ static Delegates() } static global::System.IntPtr GetFunctionByName(string functionName, global::System.IntPtr libraryHandle) - => libraryLoader.GetFunction(libraryHandle, functionName); + { + try + { + return libraryLoader.GetFunction(libraryHandle, functionName); + } + catch (MissingMethodException e) when (libraryHandle == IntPtr.Zero) + { + throw new MissingMethodException( + "Did you forget to set Runtime.PythonDLL?" + + " See https://github.com/pythonnet/pythonnet#embedding-python-in-net", + e); + } + } internal static delegate* unmanaged[Cdecl] PyDictProxy_New { get; } internal static delegate* unmanaged[Cdecl] Py_IncRef { get; }