SWI-Prolog / contrib-swiplcs

Interface from C# to SWI-Prolog
http://www.lesta.de/Prolog/SwiPlCs/Generated/Index.html
24 stars 10 forks source link

Attempted to read or write protected memory. #1

Open 1rosehip opened 10 years ago

1rosehip commented 10 years ago

Hello, Thank you for the useful library. I try to run "HelloWorldDemo" example from documentation and get the following error:

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at System.Runtime.InteropServices.Marshal.WriteInt64(IntPtr ptr, Int32 ofs, Int64 val) at System.Runtime.InteropServices.Marshal.WriteIntPtr(IntPtr ptr, IntPtr val) at SbsSW.SwiPlCs.libpl.SetStreamFunction(PlStreamType streamType, StreamsFunction functionType, Delegate function) at SbsSW.SwiPlCs.PlEngine.Initialize(String[] argv)

I use Visual Sudio 2010

Do you have any ideas?

Thank you

UweLesta commented 10 years ago

Hello Miriam,

You are welcome. If the 'HelloWorldDemo' do not work it is probably a version mismatch.

Please Answer the following questions:

1) Which version of SWI-Prolog do you use? (query for ?- version. (number and 32 or 64 bit version))

2) Against which .net framework version do you compile? (also version number and 32 or 64 bit)

3) which version of SwiPlCs.dll do you use? Or did you compile it from the sources? If yes with which properties? (you can determine the version of SwiPlCs.dll if you right click on the file - properties - details - Fileversion or Productversion)

With the information above I can assist you to get it running.

Uwe

-----Original Message----- From: Miriam Zusin [mailto:notifications@github.com] Sent: Tuesday, August 05, 2014 10:31 AM To: SWI-Prolog/contrib-swiplcs Subject: [contrib-swiplcs] Attempted to read or write protected memory. (#1)

Hello, Thank you for the useful library. I try to run "HelloWorldDemo" example from documentation and get the following error:

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at System.Runtime.InteropServices.Marshal.WriteInt64(IntPtr ptr, Int32 ofs, Int64 val) at System.Runtime.InteropServices.Marshal.WriteIntPtr(IntPtr ptr, IntPtr val) at SbsSW.SwiPlCs.libpl.SetStreamFunction(PlStreamType streamType, StreamsFunction functionType, Delegate function) at SbsSW.SwiPlCs.PlEngine.Initialize(String[] argv)

I use Visual Sudio 2010

Do you have any ideas?

Thank you

— Reply to this email directly or view it on GitHub https://github.com/SWI-Prolog/contrib-swiplcs/issues/1 . https://github.com/notifications/beacon/7372553__eyJzY29wZSI6Ik5ld3NpZ XM6QmVhY29uIiwiZXhwaXJlcyI6MTcyMjg0NjY4NCwiZGF0YSI6eyJpZCI6Mzg4MjQ5NzZ9 fQ==--3db03d741e8468433fd7418bd4e97eb712b1eba2.gif

1rosehip commented 10 years ago

Thank you for the fast reply.

My details: SWI-Prolog: Multi-threaded, 64 bits, Version 6.6.6 DOT.NET version: v4.0.30319, 64 bit I use SwiPlCs 1.1.60301.0 downloaded from website

UweLesta commented 10 years ago

Ok, 1.1.60301.0 is nearly 2 years old.

Please be so kind and try version 1.1.60605.0 (SwiPlCs64.dll 64-bit) From http://www.lesta.de/Prolog/SwiPlCs/Generated/Index.html Download page: http://www.lesta.de/Prolog/SwiPlCs/download/index.htm

Don’t be afraid that I call it a beta-version. It seems to be stabile.

If you have any further problems or questions don't hesitate to send me a mail.

Uwe

-----Original Message----- From: Miriam Zusin [mailto:notifications@github.com] Sent: Tuesday, August 05, 2014 9:04 PM To: SWI-Prolog/contrib-swiplcs Cc: Uwe Lesta Subject: Re: [contrib-swiplcs] Attempted to read or write protected memory. (#1)

Thank you for the fast reply.

My details: SWI-Prolog: Multi-threaded, 64 bits, Version 6.6.6 DOT.NET version: v4.0.30319, 64 bit I use SwiPlCs 1.1.60301.0 downloaded from website

— Reply to this email directly or view it on GitHub https://github.com/SWI-Prolog/contrib-swiplcs/issues/1#issuecomment- 51243921 . https://github.com/notifications/beacon/7372553__eyJzY29wZSI6Ik5ld3NpZ XM6QmVhY29uIiwiZXhwaXJlcyI6MTcyMjg4NDYxMiwiZGF0YSI6eyJpZCI6Mzg4MjQ5NzZ9 fQ==--42a56a2935e7e724747742680a37d22d4fe7e2ee.gif

1rosehip commented 10 years ago

I did not realize that this version is so old :) With the new version I get the following error:

The specified module could not be found. (Exception from HRESULT: 0x8007007E) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 e rrorCode, IntPtr errorInfo) at SbsSW.SwiPlCs.PlEngine.Initialize(String[] argv) at prolog_test.Program.Main(String[] args) in C:\inetpub\wwwroot\codelib\libr ary\prolog\test-programs\prolog-test\prolog-test\Program.cs:line 19

I searched for this issue in google and found that I should set SWI_HOME_DIR variable in PATH but it still doesn't work.

Maybe you have an idea how to fix it? My OS is Windows 7

1rosehip commented 10 years ago

I've also found the following question in stackoverflow with the same issue: http://stackoverflow.com/questions/13556887/interface-prolog-with-c-sharp

JanWielemaker commented 10 years ago

On 08/06/2014 07:34 AM, Miriam Zusin wrote:

I did not realize that this version is so old :) With the new version I get the following error:

The specified module could not be found. (Exception from HRESULT: 0x8007007E) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 e rrorCode, IntPtr errorInfo) at SbsSW.SwiPlCs.PlEngine.Initialize(String[] argv) at prolog_test.Program.Main(String[] args) in C:\inetpub\wwwroot\codelib\libr ary\prolog\test-programs\prolog-test\prolog-test\Program.cs:line 19

I searched for this issue in google and found that I should set SWI_HOME_DIR variable in PATH but it still doesn't work.

You should add the folder holding libswipl.dll to %PATH%. By default, this is C:\Program Files\swipl\bin. Check this first. You can find the location of the executable using

?- current_prolog_flag(executable, Exe).

libswipl.dll should be in the same folder. Do not copy these things around, as libswipl.dll is used to locate the remainder of the system.

You should only mess around with the location of the SWI-Prolog components if you want to make a distributable binary that does not include the whole Prolog distribution. That is an entirely different matter. As long as you don't, make sure there is only one libswipl.dll on your system, that it is inside the distribution tree and that its folder is in %PATH%. Many other configurations can work, but require good understanding of Window's and SWI-Prolog's search for components.

Make sure there is no %SWI_HOME_DIR%. It is only needed if you need more complicated scenarios.

Cheers --- Jan

Maybe you have an idea how to fix it? My OS is Windows 7

— Reply to this email directly or view it on GitHub https://github.com/SWI-Prolog/contrib-swiplcs/issues/1#issuecomment-51295522.

1rosehip commented 10 years ago

It works for me now, Thank you very much!

Just one additional thing I had to do to make it work: I renamed SwiPlCs64.dll to SwiPlCs.dll otherwise I still get an error "Attempted to read or write protected memory."

hiiamjack99 commented 3 years ago

Xin chào Miriam,

Không có gì. Nếu 'HelloWorldDemo' không hoạt động, nó có thể là phiên bản không khớp.

Hãy trả lời những câu hỏi sau đây:

  1. Bạn sử dụng phiên bản SWI-Prolog nào? (truy vấn cho? - phiên bản. (số và phiên bản 32 hoặc 64 bit))
  2. Bạn biên dịch phiên bản khung .net nào? (cả số phiên bản và 32 hoặc 64 bit)
  3. bạn sử dụng phiên bản SwiPlCs.dll nào? Hay bạn đã biên dịch nó từ các nguồn? Nếu có với những thuộc tính nào? (bạn có thể xác định phiên bản của SwiPlCs.dll nếu bạn nhấp chuột phải vào tệp - thuộc tính - chi tiết - Fileversion hoặc Productversion)

Với thông tin trên, tôi có thể giúp bạn chạy nó.

Uwe

----- Tin nhắn gốc ----- Từ: Miriam Zusin [mailto: notification@github.com ] Đã gửi: Thứ Ba, ngày 05 tháng 8 năm 2014 10:31 SA Tới: SWI-Prolog / Contrib-swiplcs Chủ đề: [đóng góp -swiplcs] Đã cố đọc hoặc ghi bộ nhớ được bảo vệ. ( # 1 ) Xin chào, Cảm ơn bạn đã có thư viện hữu ích. Tôi cố gắng chạy ví dụ "HelloWorldDemo" từ tài liệu và gặp lỗi sau: Ngoại lệ không được xử lý: System.AccessViolationException: Đã cố gắng đọc hoặc ghi bộ nhớ được bảo vệ. Đây thường là dấu hiệu cho thấy bộ nhớ khác bị hỏng. tại System.Runtime.InteropServices.Marshal.WriteInt64 (IntPtr ptr, Int32 ofs, Int64 val) tại System.Runtime.InteropServices.Marshal.WriteIntPtr (IntPtr ptr, IntPtr val) tại SbsSW.SwiPlCStunctions.libpl.SetStreamF Streams, Plunctions. functionType, Delegate function) tại SbsSW.SwiPlCs.PlEngine.Initialize (String [] argv) Tôi sử dụng Visual Sudio 2010 Bạn có bất cứ ý tưởng? Cảm ơn bạn

Thanks very much. I love U <3

rjsargeant commented 2 years ago

I am trying to set up the swiPlCs interface but I have been unable to resolve a persistent System.AccessViolationException. I am using the latest version 60605 version. I have included the swi-prolog bin directory in the path variable. The sample program is reading the swiPLCs DLL as demonstrated in intellisense. I am using the 64 bit dll, 64 bit swi-prolog, and .Net 5. I have tried the other various fixes such as renaming the 64 bit dll and adding the SWI_HOME_DIR variable. I have tried earlier versions of the swiPICs but with the same error. Any thoughts would be appreciated.

JanWielemaker commented 2 years ago

Not sure, but you may have to recompile the C# binding. The SWI-Prolog API is often not binary compatible between major versions. It is usually source code compatible. Another possible issue is that SWI-Prolog precompiled binaries are compiled with MinGW64 (GCC for Windows) rather than VS. I'm not sure about the compatibility (any Windows gurus?) Otherwise I guess you need a debugger.