Can';t从C#应用程序调用Clojure clr静态方法
我遇到异常非静态字段、方法或…需要对象引用 以下是我试图做的:Can';t从C#应用程序调用Clojure clr静态方法,c#,.net,clojure,clojureclr,C#,.net,Clojure,Clojureclr,我遇到异常非静态字段、方法或…需要对象引用 以下是我试图做的: ;; Here's the program.clj file from a VsClojure project. ;; First thing you need to do is add the :methods property ;; which takes a of methods that are to be generated when ;; the class is created. Here, I'm generati
;; Here's the program.clj file from a VsClojure project.
;; First thing you need to do is add the :methods property
;; which takes a of methods that are to be generated when
;; the class is created. Here, I'm generating a static method
;; named hi which has no parameters and returns a String.
;;
;; When program.hi() is called from the C# code the
;; the clojure function -hi will be called. By default any
;; method in the :methods vector will be mapped to a function
;; with the same name prefixed by a -.
(ns program
(:gen-class
:methods [ #^{:static true} [hi [] String]]))
(defn -hi []
"Hi from ClojureCLR!")
(defn -main [& args]
(println "Hello world")
(println (-hi)))
;; The C# code is nothing special
;; You MUST add both the program.exe and program.clj.dll
;; files as references in hte C# project. In addition
;; to these assemblies you'll need to add the following
;; assemblies which can be found in the ClojureCLR's directory:
;; clj.gen_class.clj.dll, clojure.clr.io.clj.dll, clojure.core.clj.dll
;; clojure.core_deftype.clj.dll, clojure.core_printl.clj.dll,
;; clojure.core_proxy.clj.dll, clojure.genclass.clj.dll, clojure.gvec.clj.dll
;; using System;
;; namespace csharp
;; {
;; class Program
;; {
;; static void Main(string[] args)
;; {
;; // You can see here you'd never know this was
;; // really a clojure function I'm calling
;; Console.WriteLine("p.hi => {0}", program.hi());
;; }
;; }
;;}
但得到:错误1非静态字段、方法或属性“program.hi()”ConsoleApplication1需要对象引用。
我这里也有:
我正在使用内置的Visual Studio扩展vsClojure。1.1.0; GitHub自述文件之后的最新版本1.1.0。也许我需要更新它,但我有一些小的本地问题,这使我不能构建最后一个clojre clr(我将在明年解决它们)
所以问题是我如何从C#调用clojure clr库?我的麻烦在哪里
日志:
在c#项目中,您是否有对program.exe和program.clj.dll的引用?如果您自己构建clojure项目并运行它,它对您有用吗 您可以尝试的另一件事是在获取最新的二进制版本。一旦设置完成,请执行以下操作:
罗布我对这两个都有提及。据我记忆所及,第一个示例中的start program.exe上是app崩溃,而one.exe上是appcrash。Clojure.compile.exe输出:D:\nCdy\Clojure clr intro\3-calling-Clojure-from-c-sharp\clj\one>Clojure.compile.exe一个编译一个到。--797毫秒。但是当尝试从C#运行时,无法运行一个.exe(因为appcrash)和绝对相同的“非静态字段必需”。我将尝试发现更多信息。您能告诉我运行时出现的错误吗?你能运行clojure.main.exe而不出错吗?我可以从visual studio运行它,但当我直接运行program.exe时,我在kernelbase.dll上得到appcrash:System.TypeInitializationException未处理。消息:类型初始值设定项“program”引发异常。我还在问题中添加了加载日志。在visual studio之外,如果从命令提示符运行clojure.main.exe会发生什么?它能正常启动吗?如果是这样的话,它说你正在运行的clojure版本是什么?在C#项目中,你有哪些参考资料?将它们与我在最新博客文章中列出的进行比较。
'program.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'program.exe' (Managed (v2.0.50727)): Loaded 'D:\nCdy\P\Clojure1\Clojure1\bin\Debug\program.exe', Symbols loaded.
'program.exe' (Managed (v2.0.50727)): Loaded 'D:\nCdy\P\Clojure1\Clojure1\bin\Debug\Clojure.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'program.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'program.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'program.exe' (Managed (v2.0.50727)): Loaded 'D:\nCdy\P\Clojure1\Clojure1\bin\Debug\Microsoft.Scripting.ExtensionAttribute.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'program.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\mscorlib.resources\2.0.0.0_ru_b77a5c561934e089\mscorlib.resources.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.