clojureclr

How To Invoke GetCurrentDirectory Method in Clojure CLR?


I am just trying out Clojure CLR a bit and I am stumped about how to make what seems as if it should be a pretty simple call work.

Version is Clojure 1.10.0-master-SNAPSHOT

In the REPL I do this:

(import 'System.IO.FileSystem)
(FileSystem/Directory/GetCurrentDirectory)

I get the following response:

Syntax error (InvalidOperationException) compiling at (REPL:1:2).
Unable to find static field: GetCurrentDirectory in

Everything I can find about "Unable to find static field:" would seem to indicate that I've got the assembly name wrong but that doesn't seem to be it.

I also tried this:

(. FileSystem/Directory GetCurrentDirectory)

and I get

Syntax error (InvalidOperationException) compiling at (REPL:1:2).
Unable to find static field: Directory in System.IO.FileSystem

Also tried this:

(FileSystem/Directory/GetCurrentDirectory [])

And I get this error:

Syntax error (InvalidOperationException) compiling at (REPL:1:2).
Unable to find static field: GetCurrentDirectory in

Can someone please tell me what it is that I've gotten wrong here?


Solution

  • Under Core 3.1 and Net 5.0, System.IO.FileSystem does not contain GetCurrenDirectory or Directory. (You can check this quickly by evaling ((map #(.Name %) (concat (.GetMethods System.IO.FileSystem) (.GetProperties System.IO.FileSystem)) to see what's available.)

    There is a System.IO.Directory class with a GetCurrentDirectory method. Try

    (System.IO.Directory/GetCurrentDirectory)
    

    or if you prefer to import the class

    (import 'System.IO.Directory)
    (Directory/GetCurrentDirectory)