我得到異常的對象引用需要非靜態字段,方法,或...無法調用CLR的Clojure從C#應用程序的靜態方法
這裏什麼我試圖做:
;; 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庫,我的麻煩在哪裏?
日誌:
'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.
我有兩個引用。據我記得這是應用程序崩潰在第一個例子上啓動program.exe並確保one.exe上的appcrash。 Clojure.compile.exe輸出:D:\ nCdy \ clojure-clr-intro \ 3-calling-clojure-from -c-sharp \ clj \ one> Clojure.Compile.exe一個 編譯一個。 - 797毫秒。但是當試圖從C#運行時,無法運行one.exe(因爲appcrash)和絕對相同的「非靜態字段所需的」。我會盡力發現更多信息。 – Cynede 2011-12-20 12:54:15
當你運行它時,你能告訴我你得到的錯誤嗎?你能沒有錯誤地運行clojure.main.exe? – Rob 2011-12-22 19:58:29
我可以從visual studio運行它,但是當我直接運行program.exe時,我在kernelbase.dll上得到了appcrash:System.TypeInitializationException未處理。消息:鍵入初始化程序「程序」引發異常。我還添加了加載日誌到問題。 – Cynede 2011-12-23 04:05:12