Unable to load foreign library (CORECLR). (on Windows 10)
johnhilts opened this issue ยท 8 comments
When I try running (QL:QUICKLOAD :BIKE), I see this error message: "Unable to load foreign library (CORECLR)."
Any ideas?
Complete Error Message:
Unable to load foreign library (CORECLR).
Error opening shared object "C:\Program Files\dotnet\shared\Microsoft.NETCore.App\6.0.4\coreclr.dll":
%1 is not a valid Win32 application.
[Condition of type CFFI:LOAD-FOREIGN-LIBRARY-ERROR]
Environment:
Windows 10
.NET 6
SBCL 2.2.4
Emacs 26.3
Backtrace: generated by calling: (sb-debug:backtrace-as-list)
(((LAMBDA (#:G1)
:IN
"C:/Users/JohnH/quicklisp/dists/quicklisp/software/bike-20211020-git/src/libraries.lisp")
#)
(SWANK::EVAL-IN-FRAME-AUX 0 "(sb-debug:backtrace-as-list)" "CFFI"
#)
(SB-INT:SIMPLE-EVAL-IN-LEXENV
(SWANK:EVAL-STRING-IN-FRAME "(sb-debug:backtrace-as-list)" 0 "CFFI")
#)
(EVAL (SWANK:EVAL-STRING-IN-FRAME "(sb-debug:backtrace-as-list)" 0 "CFFI"))
(SWANK:EVAL-FOR-EMACS
(SWANK:EVAL-STRING-IN-FRAME "(sb-debug:backtrace-as-list)" 0 "CFFI")
"COMMON-LISP-USER" 32)
(SWANK::SLDB-LOOP 1)
((FLET SWANK/BACKEND:CALL-WITH-DEBUGGING-ENVIRONMENT :IN "C:/Users/JohnH/quicklisp/dists/quicklisp/software/slime-v2.27/swank/sbcl.lisp")
#<FUNCTION (LAMBDA () :IN SWANK::DEBUG-IN-EMACS) {2480637D}>)
(SWANK::DEBUG-IN-EMACS
#<CFFI:LOAD-FOREIGN-LIBRARY-ERROR "Unable to load foreign library (A).% ~A" {28DAAE09}>)
(SWANK:INVOKE-SLIME-DEBUGGER
#<CFFI:LOAD-FOREIGN-LIBRARY-ERROR "Unable to load foreign library (A).% ~A" {28DAAE09}>)
(SWANK/SBCL::CALL-WITH-BREAK-HOOK #
#<FUNCTION (LAMBDA ()
:IN
SWANK:SWANK-DEBUGGER-HOOK) {28DAB325}>)
((FLET SWANK/BACKEND:CALL-WITH-DEBUGGER-HOOK :IN "C:/Users/JohnH/quicklisp/dists/quicklisp/software/slime-v2.27/swank/sbcl.lisp")
#
#<FUNCTION (LAMBDA () :IN SWANK:SWANK-DEBUGGER-HOOK) {28DAB325}>)
(SWANK:SWANK-DEBUGGER-HOOK
#<CFFI:LOAD-FOREIGN-LIBRARY-ERROR "Unable to load foreign library (A).% ~A" {28DAAE09}>
#)
(SB-DEBUG::RUN-HOOK DEBUGGER-HOOK
#<CFFI:LOAD-FOREIGN-LIBRARY-ERROR "Unable to load foreign library (A).% ~A" {28DAAE09}>)
(INVOKE-DEBUGGER
#<CFFI:LOAD-FOREIGN-LIBRARY-ERROR "Unable to load foreign library (A).% ~A" {28DAAE09}>)
(ERROR CFFI:LOAD-FOREIGN-LIBRARY-ERROR :FORMAT-CONTROL
"Unable to load foreign library (A).% ~A" :FORMAT-ARGUMENTS
(BIKE::CORECLR
"Error opening shared object "C:\\Program Files\\dotnet\\shared\\Microsoft.NETCore.App\\6.0.4\\coreclr.dll":
%1 is not a valid Win32 application."))
(CFFI::FL-ERROR "Unable to load foreign library (A).% ~A" BIKE::CORECLR
"Error opening shared object "C:\\Program Files\\dotnet\\shared\\Microsoft.NETCore.App\\6.0.4\\coreclr.dll":
%1 is not a valid Win32 application.")
(CFFI::REPORT-SIMPLE-ERROR BIKE::CORECLR
#<SIMPLE-ERROR "Error opening shared object ~S:
~A" {28DAA8F9}>)
((FLET CFFI::%DO-LOAD :IN CFFI::%DO-LOAD-FOREIGN-LIBRARY)
#<CFFI:FOREIGN-LIBRARY CORECLR> BIKE::CORECLR "coreclr.dll")
(CFFI:LOAD-FOREIGN-LIBRARY BIKE::CORECLR :SEARCH-PATH NIL)
(SB-INT:SIMPLE-EVAL-IN-LEXENV (CFFI:LOAD-FOREIGN-LIBRARY 'BIKE::CORECLR)
#)
(SB-INT:SIMPLE-EVAL-IN-LEXENV
(PROGN (CFFI:LOAD-FOREIGN-LIBRARY 'BIKE::CORECLR)) #)
(EVAL-TLF (PROGN (CFFI:LOAD-FOREIGN-LIBRARY 'BIKE::CORECLR)) 2
#)
((FLET SB-C::FROB :IN SB-C::EVAL-COMPILE-TOPLEVEL))
(SB-C::EVAL-COMPILE-TOPLEVEL ((CFFI:LOAD-FOREIGN-LIBRARY 'BIKE::CORECLR))
((CFFI:LOAD-FOREIGN-LIBRARY 'BIKE::CORECLR)
SB-C::ORIGINAL-SOURCE-START 4 3 2))
(SB-C::PROCESS-TOPLEVEL-FORM (CFFI:LOAD-FOREIGN-LIBRARY 'BIKE::CORECLR)
(SB-C::ORIGINAL-SOURCE-START 4 3 2)
(:COMPILE-TOPLEVEL))
(SB-C::PROCESS-TOPLEVEL-FORM (CFFI:USE-FOREIGN-LIBRARY BIKE::CORECLR)
(SB-C::ORIGINAL-SOURCE-START 0 2)
(:COMPILE-TOPLEVEL))
(SB-C::PROCESS-TOPLEVEL-PROGN
((CFFI:DEFINE-FOREIGN-LIBRARY BIKE::CORECLR
(T "coreclr.dll"))
(CFFI:USE-FOREIGN-LIBRARY BIKE::CORECLR))
(SB-C::ORIGINAL-SOURCE-START 0 2) (:COMPILE-TOPLEVEL))
(SB-C::PROCESS-TOPLEVEL-FORM
(EVAL-WHEN (:COMPILE-TOPLEVEL :LOAD-TOPLEVEL :EXECUTE)
(CFFI:DEFINE-FOREIGN-LIBRARY BIKE::CORECLR
(T "coreclr.dll"))
(CFFI:USE-FOREIGN-LIBRARY BIKE::CORECLR))
(SB-C::ORIGINAL-SOURCE-START 0 2) NIL)
((LAMBDA (SB-KERNEL:FORM &KEY :CURRENT-INDEX &ALLOW-OTHER-KEYS)
:IN
SB-C::SUB-COMPILE-FILE)
(EVAL-WHEN (:COMPILE-TOPLEVEL :LOAD-TOPLEVEL :EXECUTE)
(CFFI:DEFINE-FOREIGN-LIBRARY BIKE::CORECLR
(T "coreclr.dll"))
(CFFI:USE-FOREIGN-LIBRARY BIKE::CORECLR))
:CURRENT-INDEX 2)
(SB-C::%DO-FORMS-FROM-INFO
#<FUNCTION (LAMBDA (SB-KERNEL:FORM &KEY :CURRENT-INDEX &ALLOW-OTHER-KEYS)
:IN
SB-C::SUB-COMPILE-FILE) {230D8C25}>
#<SB-C::SOURCE-INFO {28D0AB79}> SB-C::INPUT-ERROR-IN-COMPILE-FILE)
((FLET "LAMBDA0" :IN "SYS:SRC;COMPILER;MAIN.LISP"))
((FLET SB-C::WITH-IT :IN SB-C::%WITH-COMPILATION-UNIT))
(SB-C::SUB-COMPILE-FILE #<SB-C::SOURCE-INFO {28D0AB79}> NIL)
(SB-C::%COMPILE-FILES
(#P"C:/Users/JohnH/quicklisp/dists/quicklisp/software/bike-20211020-git/src/libraries.lisp")
:UTF-8 T
#P"C:/Users/JohnH/AppData/Local/cache/common-lisp/sbcl-2.2.4-win-x86/C/Users/JohnH/quicklisp/dists/quicklisp/software/bike-20211020-git/src/libraries-tmpMO2T7PGC.fasl"
NIL NIL)
(COMPILE-FILE
#P"C:/Users/JohnH/quicklisp/dists/quicklisp/software/bike-20211020-git/src/libraries.lisp"
:OUTPUT-FILE
#P"C:/Users/JohnH/AppData/Local/cache/common-lisp/sbcl-2.2.4-win-x86/C/Users/JohnH/quicklisp/dists/quicklisp/software/bike-20211020-git/src/libraries-tmpMO2T7PGC.fasl"
:VERBOSE NIL :PRINT NIL :EXTERNAL-FORMAT :UTF-8 :PROGRESS NIL :TRACE-FILE
NIL :BLOCK-COMPILE NIL :ENTRY-POINTS NIL :EMIT-CFASL NIL)
(UIOP/UTILITY:CALL-WITH-MUFFLED-CONDITIONS
#<FUNCTION (LAMBDA () :IN UIOP/LISP-BUILD:COMPILE-FILE*) {28D09345}> NIL)
(UIOP/PATHNAME:CALL-WITH-ENOUGH-PATHNAME
#P"C:/Users/JohnH/quicklisp/dists/quicklisp/software/bike-20211020-git/src/libraries.lisp"
NIL
#<FUNCTION (LAMBDA (UIOP/LISP-BUILD::INPUT-FILE)
:IN
UIOP/LISP-BUILD:COMPILE-FILE*) {28D09305}>)
(UIOP/LISP-BUILD:COMPILE-FILE*
#P"C:/Users/JohnH/quicklisp/dists/quicklisp/software/bike-20211020-git/src/libraries.lisp"
:OUTPUT-FILE
#P"C:/Users/JohnH/AppData/Local/cache/common-lisp/sbcl-2.2.4-win-x86/C/Users/JohnH/quicklisp/dists/quicklisp/software/bike-20211020-git/src/libraries.fasl"
:EXTERNAL-FORMAT :UTF-8 :WARNINGS-FILE NIL)
(ASDF/LISP-ACTION:PERFORM-LISP-COMPILATION #<ASDF/LISP-ACTION:COMPILE-OP >
#<ASDF/LISP-ACTION:CL-SOURCE-FILE "bike" "src" "libraries">)
((SB-PCL::EMF ASDF/ACTION:PERFORM) # #
#<ASDF/LISP-ACTION:COMPILE-OP >
#<ASDF/LISP-ACTION:CL-SOURCE-FILE "bike" "src" "libraries">)
((LAMBDA () :IN ASDF/ACTION:CALL-WHILE-VISITING-ACTION))
((:METHOD ASDF/ACTION:PERFORM-WITH-RESTARTS :AROUND (T T))
#<ASDF/LISP-ACTION:COMPILE-OP >
#<ASDF/LISP-ACTION:CL-SOURCE-FILE "bike" "src" "libraries">)
((:METHOD ASDF/PLAN:PERFORM-PLAN (T))
#<ASDF/PLAN:SEQUENTIAL-PLAN {288AAF91}>)
((FLET SB-C::WITH-IT :IN SB-C::%WITH-COMPILATION-UNIT))
((:METHOD ASDF/PLAN:PERFORM-PLAN :AROUND (T))
#<ASDF/PLAN:SEQUENTIAL-PLAN {288AAF91}>)
((:METHOD ASDF/OPERATE:OPERATE
(ASDF/OPERATION:OPERATION ASDF/COMPONENT:COMPONENT))
#<ASDF/LISP-ACTION:LOAD-OP > #<ASDF/SYSTEM:SYSTEM "bike"> :PLAN-CLASS NIL
:PLAN-OPTIONS NIL)
((SB-PCL::EMF ASDF/OPERATE:OPERATE) # #
#<ASDF/LISP-ACTION:LOAD-OP > #<ASDF/SYSTEM:SYSTEM "bike"> :VERBOSE NIL)
((LAMBDA () :IN ASDF/OPERATE:OPERATE))
((:METHOD ASDF/OPERATE:OPERATE :AROUND (T T)) #<ASDF/LISP-ACTION:LOAD-OP >
#<ASDF/SYSTEM:SYSTEM "bike"> :VERBOSE NIL)
((SB-PCL::EMF ASDF/OPERATE:OPERATE) # #
ASDF/LISP-ACTION:LOAD-OP "bike" :VERBOSE NIL)
((LAMBDA () :IN ASDF/OPERATE:OPERATE))
((:METHOD ASDF/OPERATE:OPERATE :AROUND (T T)) ASDF/LISP-ACTION:LOAD-OP
"bike" :VERBOSE NIL)
(ASDF/SESSION:CALL-WITH-ASDF-SESSION
#<FUNCTION (LAMBDA () :IN ASDF/OPERATE:OPERATE) {288A418D}> :OVERRIDE T
:KEY NIL :OVERRIDE-CACHE T :OVERRIDE-FORCING NIL)
((LAMBDA () :IN ASDF/OPERATE:OPERATE))
(ASDF/SESSION:CALL-WITH-ASDF-SESSION
#<FUNCTION (LAMBDA () :IN ASDF/OPERATE:OPERATE) {2889CA5D}> :OVERRIDE NIL
:KEY NIL :OVERRIDE-CACHE NIL :OVERRIDE-FORCING NIL)
((:METHOD ASDF/OPERATE:OPERATE :AROUND (T T)) ASDF/LISP-ACTION:LOAD-OP
"bike" :VERBOSE NIL)
(ASDF/OPERATE:LOAD-SYSTEM "bike" :VERBOSE NIL)
(QUICKLISP-CLIENT::CALL-WITH-MACROEXPAND-PROGRESS
#<FUNCTION (LAMBDA ()
:IN
QUICKLISP-CLIENT::APPLY-LOAD-STRATEGY) {2889C965}>)
(QUICKLISP-CLIENT::AUTOLOAD-SYSTEM-AND-DEPENDENCIES "bike" :PROMPT NIL)
((:METHOD QL-IMPL-UTIL::%CALL-WITH-QUIET-COMPILATION (T T))
#
#<FUNCTION (FLET QUICKLISP-CLIENT::QL :IN QUICKLISP-CLIENT:QUICKLOAD) {28890BAD}>)
((:METHOD QL-IMPL-UTIL::%CALL-WITH-QUIET-COMPILATION :AROUND
(QL-IMPL:SBCL T))
#<QL-IMPL:SBCL {25AEE931}>
#<FUNCTION (FLET QUICKLISP-CLIENT::QL :IN QUICKLISP-CLIENT:QUICKLOAD) {28890BAD}>)
((:METHOD QUICKLISP-CLIENT:QUICKLOAD (T)) :BIKE :PROMPT NIL :SILENT NIL
:VERBOSE NIL)
(QL-DIST::CALL-WITH-CONSISTENT-DISTS
#<FUNCTION (LAMBDA () :IN QUICKLISP-CLIENT:QUICKLOAD) {2888C79D}>)
(SB-INT:SIMPLE-EVAL-IN-LEXENV (QUICKLISP-CLIENT:QUICKLOAD :BIKE)
#)
(EVAL (QUICKLISP-CLIENT:QUICKLOAD :BIKE))
(SWANK::EVAL-REGION "(ql:quickload :bike)
")
((LAMBDA () :IN SWANK-REPL::REPL-EVAL))
(SWANK-REPL::TRACK-PACKAGE
#<FUNCTION (LAMBDA () :IN SWANK-REPL::REPL-EVAL) {2888C735}>)
(SWANK::CALL-WITH-RETRY-RESTART "Retry SLIME REPL evaluation request."
#<FUNCTION (LAMBDA ()
:IN
SWANK-REPL::REPL-EVAL) {2888C705}>)
(SWANK::CALL-WITH-BUFFER-SYNTAX NIL
#<FUNCTION (LAMBDA ()
:IN
SWANK-REPL::REPL-EVAL) {2888C6F5}>)
(SWANK-REPL::REPL-EVAL "(ql:quickload :bike)
")
(SB-INT:SIMPLE-EVAL-IN-LEXENV
(SWANK-REPL:LISTENER-EVAL "(ql:quickload :bike)
")
#)
(EVAL
(SWANK-REPL:LISTENER-EVAL "(ql:quickload :bike)
"))
(SWANK:EVAL-FOR-EMACS
(SWANK-REPL:LISTENER-EVAL "(ql:quickload :bike)
")
"COMMON-LISP-USER" 24)
(SWANK::PROCESS-REQUESTS NIL) ((LAMBDA () :IN SWANK::HANDLE-REQUESTS))
((LAMBDA () :IN SWANK::HANDLE-REQUESTS))
(SWANK/SBCL::CALL-WITH-BREAK-HOOK #
#<FUNCTION (LAMBDA ()
:IN
SWANK::HANDLE-REQUESTS) {24FC007D}>)
((FLET SWANK/BACKEND:CALL-WITH-DEBUGGER-HOOK :IN "C:/Users/JohnH/quicklisp/dists/quicklisp/software/slime-v2.27/swank/sbcl.lisp")
#
#<FUNCTION (LAMBDA () :IN SWANK::HANDLE-REQUESTS) {24FC007D}>)
(SWANK::CALL-WITH-BINDINGS
((STANDARD-INPUT . #<SWANK/GRAY::SLIME-INPUT-STREAM {24DC8689}>))
#<FUNCTION (LAMBDA () :IN SWANK::HANDLE-REQUESTS) {24FC008D}>)
(SWANK::HANDLE-REQUESTS #<SWANK::MULTITHREADED-CONNECTION {24518F51}> NIL)
((FLET SB-UNIX::BODY :IN SB-THREAD::RUN))
((FLET "WITHOUT-INTERRUPTS-BODY-9" :IN SB-THREAD::RUN))
(SB-THREAD::RUN #<SB-THREAD:THREAD "repl-thread" RUNNING {24FB91C1}> NIL
#<FUNCTION (LAMBDA ()
:IN
SWANK-REPL::SPAWN-REPL-THREAD) {24FB9145}>
NIL)
((FLET "WITHOUT-INTERRUPTS-BODY-1" :IN SB-THREAD::START-THREAD))
((FLET SB-THREAD::START-ROUTINE :IN SB-THREAD::START-THREAD))
("foreign function: #x42D25D") ("foreign function: #x404309")
("foreign function: #x4183B5"))
@johnhilts Hello! This type of error usually occurs due to 32/64 platform mismatch. Please ensure that you are using both x64 SBCL and x64 .NET.
The library currently guesses the installed .NET version using the dotnet
command, so in case of x64 system, there's a big chance of it finding only x64 runtime. I'll try to improve .NET runtime search in the future, though.
@Lovesan - thank you for the reply - making sure I had 64 bit SBCL got me past the original error I posted.
Then, I ran (ql:quickload :bike)
, and I saw this error:
.Net exception System.BadImageFormatException
Could not load file or assembly 'System.IO.Compression.Native, Culture=neutral, PublicKeyToken=null'. The module was expected to contain an assembly manifest.
The first restart was 0: [TRY-RECOMPILING] Recompile assemblies and try loading it again
So, I tried that, and it seemed to complete without any further issues.
Now, though, I don't seem to be able to access any dotnet types.
For example, this works:
(defun hello-datetime ()
(let ((now (bike:property 'System.DateTime 'Now))
(user (bike:property 'System.Environment 'UserName)))
(format t "Hello, ~a! Now is ~a"
user (bike:invoke now 'ToString "g"))))
... but, this does not work:
(defun hello ()
(bike:invoke 'System.Console 'WriteLine "Hello, World!"))
Error:
; Evaluation aborted on .Net exception System.TypeLoadException
Could not load type 'SYSTEM.CONSOLE' from assembly 'BikeInterop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
Neither does this:
(defun hello-callback ()
(let* ((os (bike:property 'RuntimeInformation 'OSDescription))
(delegate (bike:new '(System.Action :string)
(lambda (who)
(format t "Hello ~a!~%You are running .Net Core~% inside ~a ~a~% on ~a"
who
(lisp-implementation-type)
(lisp-implementation-version)
os))))
(user (bike:property 'System.Environment 'UserName)))
(bike:invoke delegate 'invoke user)))
Error:
; Evaluation aborted on .Net exception System.TypeLoadException
Could not load type 'STRING' from assembly 'BikeInterop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
Any ideas?
@johnhilts The BadImageFormatException issue has been already fixed but hasn't yet made its way to quicklisp. You can check out the latest master, however. I guess the other issues are related to this one.
Success! Once I was able to get quicklisp to find my local projects, I got the 3 examples to work! Looking forward to playing around with my own assemblies from inside emacs!!
Also, just a note for anyone else on Windows ... what emacs considers your home folder and what everything else considers to be your home folder is a little different.
I git cloned to what emacs thinks is my home folder, but everything else including QL use a different folder.
My home folder as recognized by everything besides emacs is c:\users\MY-NAME
Emacs thinks my home folder is c:\users\MY-NAME\AppData\Roaming
I had copied QL to the roaming
folder earlier in an effort to get slime to work in the first place.
I git cloned this project into roaming
.
To get QL to recognize this I was able to update QL's list of folders it looks at.
Here's everything I did:
(ql:uninstall :bike) ;; if already installed; you could also just restart slime, etc
(push
(make-pathname
:device "C"
:directory '(:absolute "Users" "MY-NAME" "AppData" "Roaming" "quicklisp" "local-projects"))
ql:*local-project-directories*) ;; I tried doing this with just a string path, but it busted my SLIME "Lisp connection closed unexpectedly: connection broken by remote peer"
(ql:quickload "bike")
The only oddity I noticed is that the call to Console.WriteLine
didn't output anything, but not a deal breaker since we can just use things like FORMAT
and friends ....
@johnhilts Well, Emacs, amongst other unixy things, expects HOME environment variable to be set, otherwise, it makes weird guesses. I have this env. var set to my %USERPROFILE% directory.
As for the System.Console - the reason that you get no output in emacs is that SLIME REPL output isn't bound directly to lisp process stdout(i.e. to GetStdHandle(STD_OUTPUT_HANDLE)
), but rather to a socket through which Emacs and SBCL communicate. So hence, neither System.Console nor (cffi:foreign-funcall "puts" :string "Hello, World!" :int)
would output anything to emacs.
In case of SBCL has been started directly or from another console application (e.g. powershell), System.Console would work as expected.
Good to know about that use of %USERPROFILE%! Also, thank you for the explanation about stdout and how it relates to the slime repl!
Question - does bike work with other assembly types besides .net standard 2.0 DLLs? Any support for .net 4.x?
Well, it does not support .Net Framework (i.e. 4.x and below), only .Net Standard, .Net Core(2, 3) and unified .NET assemblies(5,6, etc)
I see. I got an error message when trying to use a .NET 6 exe, but I will try it again and open another issue if I can't get past it.
Thank you for your help and responsiveness with this issue! ๐