c# - 错误:HRESULT:0x8007007E System.IO.FileNotFoundException on Prolog 和 C# 集成
问题描述
我正在尝试使用 SWI Prolog 从 C# 程序调用 Prolog 脚本文件。我从 github 下载了代码包(使用这个链接)。但是,当我尝试运行 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
}
}
}
我在网上尝试了很多解决方案,例如,在 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 社区。
解决方案
推荐阅读
- c - 为什么我不能在纯 C 中包含 AppKit,即使我可以自己声明函数?
- yaml - 在 Azure DevOps 上使用 YAML 有条件地声明变量组
- python - 从 .egg-info 名称中去除 python 版本
- javascript - 未在 react-native 中显示关键错误,创建自己的组件时
- java - 如何连接一定数量的数组?
- apache-spark - Bigquery“Getting IllegalArgumentException:Invalid Table ID”错误,同时使用查询将 bigquery 表的一部分读入 pyspark 数据帧
- roc - 如何设置 roc 曲线 pos_label !=0
- python - 如何保护烧瓶中的服务器端会话?
- macos - 无法从终端运行 curl SDK man 或 ruby
- flutter - 参数类型字符串?不能分配给参数类型“字符串”