4

I am new to Prolog and C#. When I try to integrate Prolog with C# I found some errors,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SbsSW.SwiPlCs;


namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
           // Environment.SetEnvironmentVariable("SWI_HOME_DIR", @"the_PATH_to_boot32.prc");  // or boot64.prc
            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("finished!");
            }
        }
    }
}

It is not running, Before run this I was add reference SwiPlCs.dll. But it shows error "FileNotFoundException was unhandled, The specified module could not be found. (Exception from HRESULT: 0x8007007E)".

So can anyone help me to fix this error?

I got this coding here

VMAtm
  • 27,943
  • 17
  • 79
  • 125
yk2
  • 49
  • 1
  • 12
  • 2
    Do you mean you're new to *both* Prolog *and* C#? If so, I would really try to get comfortable with *at least* one of them, ideally both of them, before you integrate them together. The exception should show which file couldn't be found, by the way - look for all the details in an error message. – Jon Skeet Jan 31 '15 at 16:43
  • There is a similar question with similar error.. pls try that http://stackoverflow.com/questions/13556887/interface-prolog-with-c-sharp – Amitd Jan 31 '15 at 16:51
  • Btw there is also a nuget package http://stackoverflow.com/questions/14555200/how-to-interfacing-swi-prolog-to-the-visual-studio-2012?rq=1 – Amitd Jan 31 '15 at 16:54
  • @JonSkeet I have basic knowledge in Prolog and I have done some projects using C#. But integration is difficult to me. Anyway Thanks for your advice. – yk2 Jan 31 '15 at 17:18

1 Answers1

4

The link you've provided has full explanation of this error:

If libswipl.dll or one of its dependencies could not found you will recive an error like System.IO.FileNotFoundException: Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E)

An other common error is:

SWI-Prolog: [FATAL ERROR:
  Could not find system resources]`  
  Failed to release stacks

To fix this add the SWI_HOME_DIR environment variable as described in SWI-Prolog FAQ FindResources with a statment like this befor calling PlEngine.Initialize.

Environment.SetEnvironmentVariable("SWI_HOME_DIR", @"the_PATH_to_boot32.prc");

This code is commented by default, Uncomment it and provide the correct path to the the_PATH_to_boot32.prc. As described in FAQ:

Solution

On Windows, it suffices to leave libswipl.dll in the installation tree (i.e., do not copy it elsewhere) and add the bin directory of the installation tree to %PATH%.

A cross-platform and robust solution is to use putenv() to put an appropriate path into the environment before calling PL_initialise().

...;
putenv("SWI_HOME_DIR=C:\\Program Files\\swipl");
if ( PL_initialise(argc, argv) )
  PL_halt(1);
...

In the final version of your application you link the saved-state to the executable (using swipl-ld or cat (Unix)) and comment the putenv() call.

VMAtm
  • 27,943
  • 17
  • 79
  • 125
  • @KALYANI YOu can set this answer as accepted if you found it useful :) – VMAtm Jan 31 '15 at 18:28
  • But i couldn't fix the error. I add the path like this, Environment.SetEnvironmentVariable("SWI_HOME_DIR", @"C:\Program Files\swipl\bin"); But nothing happend – yk2 Feb 01 '15 at 09:55
  • @KALYANI Try to remove `bin` from the path – VMAtm Feb 01 '15 at 12:12