我正在尝试使用SWI Prolog从C#程序调用Prolog脚本文件。我从github下载了代码包(使用此link)。但是,当我尝试运行HelloWorldDemo程序时,会发生以下错误:
System.IO.FileNotFoundException: 'The specified module could not be found. (Exception from HRESULT: 0x8007007E)'
第105行的以下代码:
private static void LoadUnmanagedLibrary(string fileName)
{
if (_hLibrary == null)
{
_hLibrary = NativeMethods.LoadDll(fileName);
if (_hLibrary.IsInvalid)
{
int hr = Marshal.GetHRForLastWin32Error();
Marshal.ThrowExceptionForHR(hr); //here the error occurs
}
}
}
我尝试了Internet上的许多解决方案,例如,在setenviromentvariable上提供了swi路径,但错误仍然相同。
这是HelloWorldDemo.cs的代码:
static void Main(string[] args)
{
Environment.SetEnvironmentVariable("SWI_HOME_DIR", @"C:\Program Files\swipl\"); // I also used C:\Program Files\swipl\bin and didn't help too
if (!PlEngine.IsInitialized)
{
String[] param = { "-q" }; // suppressing informational and banner messages
PlEngine.Initialize(param);
PlQuery.PlCall("assert(father(martin, inka))");
PlQuery.PlCall("assert(father(uwe, gloria))");
PlQuery.PlCall("assert(father(uwe, melanie))");
PlQuery.PlCall("assert(father(uwe, ayala))");
using (var q = new PlQuery("father(P, C), atomic_list_concat([P,' is_father_of ',C], L)"))
{
foreach (PlQueryVariables v in q.SolutionVariables)
Console.WriteLine(v["L"].ToString());
Console.WriteLine("all children from uwe:");
q.Variables["P"].Unify("uwe");
foreach (PlQueryVariables v in q.SolutionVariables)
Console.WriteLine(v["C"].ToString());
}
PlEngine.PlCleanup();
Console.WriteLine("finshed!");
}
}
那么,如何解决此问题?
注意:我正在使用Win10 x64,Visual Studio 2017社区。 p>