首页 > 解决方案 > 错误: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#prologffiswi-prolog

解决方案


推荐阅读