2

For educational purposes, one of our college subjects requires a project that integrates any instance of Prolog with any other GUI supportive language. I went with C# as I have the most experience with it. I'm trying to learn by example of my fellow college colleagues from higher years. They gave me their repos to download their code and to see how it all comes together. And this is where the problems started.

No matter what I do, what tutorial I follow, what tips from other sources I apply, the error will not change: FileNotFoundException was unhandled: An unhandled exception of type 'System.IO.FileNotFoundException' occurred in SwiPlCs.dll.

I've tried using SWI 32 bit/64 bit, VS 2015/2017 with 32/64 bit builds, redownloading the DLL as a nuget package. None of them seem to work.

        InitializeComponent();
        igra.popuniSlagalicu += igra_popuniSlagalicu;
        igra.vratiOdgovor += igra_vratiOdgovor;
        String[] param = { "-q" };
        PlEngine.Initialize(param);
        PlQuery.PlCall("use_module(sudoku)");

This is the first time I felt helpless and desperate while trying to debug code. Literally stuck on a single line for 5 days without any progress whatsoever.

sedders123
  • 791
  • 1
  • 9
  • 19
JodaVz
  • 55
  • 1
  • 4
  • Of interest: [BadImageFormatException when loading 32 bit DLL, target is x86](https://stackoverflow.com/q/2728560/1243762) – Guy Coder Dec 21 '18 at 00:40
  • Of interest: GitHub - SWI-Prolog/contrib-swiplcs - [FileLoadException #3](https://github.com/SWI-Prolog/contrib-swiplcs/issues/3) – Guy Coder Dec 21 '18 at 00:42
  • Of interest: [SWI-Prolog interface to C# and F#](http://www.swi-prolog.org/contrib/CSharp.txt) - Not most recent version, but a reference on SWI-Prolog site about the interface. – Guy Coder Dec 21 '18 at 01:13
  • Of interest: GitHub - SWI-Prolog/[contrib-swiplcs](https://github.com/SWI-Prolog/contrib-swiplcs) - Home and source code in C#. – Guy Coder Dec 21 '18 at 01:15
  • You need to change the tags for this. Even though it is related to Prolog and C# it is not a Prolog or C# problem. It is a build process problem and from the looks of the error could be something simple but not obvious as you have found. I suggest you change the tags so that other with experience in this area have eyes on it. – Guy Coder Dec 21 '18 at 12:50
  • If you could update your question with the exact steps you took so that we can recreate the problem it would help. When I say exact, I mean it needs to include the versions of every tool in the build chain, the configurations, the listings, etc. I would expect to see several pages of details listed here. If you want help than you have to help those helping you. There are not many people who can help you on this and if you make it hard for them your chance of getting help drops quickly. – Guy Coder Dec 21 '18 at 12:53

1 Answers1

1

The error is not very clear, but is caused by the fact that the program needs to know where to find the DLLs that run SWI-Prolog are located. There are a few ways to do this but the simplest is to add the directory (e.g. C:\Program Files\swipl\bin) containing the SWI-Prolog executable (swipl-win.exe) to the Windows system PATH variable.

After changing the system PATH variable you will need to restart Visual Studio if necessary.

Guy Coder
  • 24,501
  • 8
  • 71
  • 136
  • After I added this answer I checked my notes and found out that since I did this a few years ago that the code has been moved to GitHub, :) but the build process has also been modified. The old version I have builds a 32-bit and a seperate 64-bit version. The GitHub build is only for a 64-bit version from what I can tell. Most the notes I had are still valid but I am checking now against the code in GitHub. – Guy Coder Dec 21 '18 at 12:47