Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureCLR by

I am porting a C# application (AutoCAD plugin to be exact) from .NET 4.8 to .NET 8.

The code uses some Clojure CLR.
In .NET 4.8 the clojure namespaces were compiled to assemblies (.dll files) using Clojure.Compile.
At runtime, these namespaces were then loaded using clojure.lang.RT.load

However, precompiling clojure clr code is not possible in .NET 8. (https://ask.clojure.org/index.php/13866/is-still-possible-compile-cljr-files-dll-exe-dotent-and-above)

If I understood correctly, the recommended approach is to include the clojure sources with the application and then load the clojure namespaces using clojure.clr.api.Clojure class?
I could not find any examples or documentation on how to set up my application / environment so that clojure.core/load will find my .clj files.

On page
https://github.com/clojure/clojure-clr/wiki/Using-ClojureCLR-in-a-C#-project
there is instructions on how to invoke clojure.core/load

IFn load= clojure.clr.api.Clojure.var("clojure.core", "load");
load.invoke("some.thing");

However, clojure.core/load is documented to use CLASSPATH to find namespaces. Does this also apply in Cojure CLR, i.e. should I define an appropriate CLASSPATH environment variable before calling clojure.core/load ?
https://clojuredocs.org/clojure.core/load

by
Having started w/ this I did not yet get to the point where the application's own Clojure sources (or compiled binaries if that were possible) would be needed. Initializing Clojure itself seems to have problems:

clojure.clr.api.Clojure.var method (being the first method invoked from Clojure library) throws an exception. There are a couple of inner exceptions, the root cause is

    {"Could not locate clojure.core.clj.dll, clojure.core.cljc.dll, clojure/core.clj or clojure/core.cljc on load path.":null}    System.Exception {System.IO.FileNotFoundException}
Whose stack trace shows it was thrown from RT.load :
        StackTrace    "   at clojure.lang.RT.load(String relativePath, Boolean failIfNotFound)\r\n   at clojure.lang.RT.load(String relativePath)\r\n   at clojure.lang.RT..cctor()"    string

I am using the Clojure nuget 1.11.0 on .NET 8. Do I need to include something else as well? Or where might I be going wrong?
ago by
Hi Antti, did you ever resolve this issue?
I'm having similar issues trying to get something working for BricsCAD.

thanks,
Mick

1 Answer

0 votes
ago by

clojure.core/load calls RT.load as seen in the stack trace.
The set of probe paths for RT.load is

  • the directory of the domain of the thread that is running (domains really being more relevant to .NET Framework at this point)
  • the current directory
  • the directory where Clojure.dll is located
  • the directory of the entry assembly
  • all directories listed as the value of the environment variable CLOJURE_LOAD_PATH
    • this is equivalent to the classpath in Java-land.
    • separator character is System.IO.Path.PathSeparator (; on Windows)

Clearly this is not sufficiently documented. Will work on that.

...