在IronPython中添加System.Data.SQLite引用

时间:2011-01-13 17:11:22

标签: ado.net ironpython system.data.sqlite

我正在尝试使用clr.AddReference将sqlite3功能添加到我正在编写的简单IronPython程序中;但每当我尝试引用System.Data.SQLite时,我都会收到此错误:

  

追踪(最近一次通话):     文件“”,第1行,in   IOError:System.IO.IOException:无法添加对程序集System.Data.SQLite的引用      在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)
     在Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame框架)

我一直在主要测试解释器中的导入和引用,这些是我测试的行:

  

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

输入clr.AddReference行后发生错误。我如何正确添加System.Data.SQLite?

1 个答案:

答案 0 :(得分: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)。