2011-01-13 107 views
1

我正在嘗試使用clr.AddReference將sqlite3功能添加到我正在編寫的簡單IronPython程序中;但每次我嘗試引用System.Data.SQLite我得到這個錯誤:在IronPython中添加System.Data.SQLite參考

Traceback (most recent call last): File "", line 1, in IOError: System.IO.IOException: Could not add reference to assembly System.Data.SQLite
at Microsoft.Scripting.Actions.Calls.MethodCandidate.Caller.Call(Object[] args, Boolean&shouldOptimize)
at IronPython.Runtime.Types.BuiltinFunction.BuiltinFunctionCaller 2.Call1(CallSite site, CodeContext context, TFuncType func, T0 arg0)
at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at CallSite.Target(Closure , CallSite , CodeContext , Object , Object)
at IronPython.Compiler.Ast.CallExpression.Invoke1Instruction.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Runtime.FunctionCode.Call(CodeContext context)
at IronPython.Runtime.Operations.PythonOps.QualifiedExec(CodeContext context, Object code, PythonDictionary globals, Object locals)
at Microsoft.Scripting.Interpreter.ActionCallInstruction
4.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)

我一直在測試了在解釋主要是進口和引用,而這些是我行測試:

import sys
import clr
sys.path.append("C:/Program Files (x86)/SQLite.NET/bin")
clr.AddReference("System.Data.SQLite")

輸入clr.AddReference行後發生錯誤。我將如何正確添加System.Data.SQLite?

+0

我下載了SQLite.NET,你的示例代碼對我來說非常適合。仔細檢查SQLite的路徑是否正確? – Cameron 2011-01-14 05:07:26

回答

1

我的第一個猜測是,您試圖在x64(64位)進程中加載​​x86(32位)System.Data.SQLite.dll,反之亦然。 System.Data.SQLite.dll包含本機sqlite3庫,必須針對x86或x64進行編譯,因此每個CPU都有一個System.Data.SQLite.dll版本。

如果您使用控制檯,ipy.exe始終是32位(即使在64位平臺上),而ipy64.exe是AnyCPU,因此它與當前平臺相匹配。如果您託管IronPython,並且主機應用程序是AnyCPU,則需要爲正在運行的計算機加載System.Data.SQLite.dll的正確副本(或者僅強制主機應用程序x86)。