Adding System.Data.SQLite reference in IronPython
Question: I'm trying to use clr.AddReference to add sqlite3 functionality to a simple
IronPython program I'm writing; but everytime I try to reference
System.Data.SQLite I get this error:

> 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)

I've been testing out the imports and references in the interpreter mainly,
and these are the lines I test:

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

The error happens after the clr.AddReference line is entered. How would I add
System.Data.SQLite properly?


Answer: My first guess is that you're trying to load the x86 (32-bit)
System.Data.SQLite.dll in a x64 (64-bit) process, or vice versa.
System.Data.SQLite.dll contains the native sqlite3 library, which must be
compiled for x86 or x64, so there is a version of System.Data.SQLite.dll for
each CPU.

If you're using the console, ipy.exe is always 32-bit (even on 64-bit
platforms) while ipy64.exe is AnyCPU, so it matches the current platform. If
you're hosting IronPython, and the host app is AnyCPU, you need to load the
right copy of System.Data.SQLite.dll for the machine you're running on (or
just force the host app x86).

