1
votes

In my program I have this simple code:

using System;
using System.Data;
using Mono.Data.SqliteClient;

.... 
IDbConnection cnx = new SqliteConnection("URI=file:reestr.db");
cnx.Open();
....

And this is how I compile it:

$ mcs Test.cs -r:System.Data.dll -r:mono.data.sqliteclient.dll

It compiles ok. But when I run it with ./Test.exe, I get this error messages:

Missing method .ctor in assembly .... Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Mono.Data.SqliteClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' or one of its dependencies. File name: 'Mono.Data.SqliteClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756'

I'm not sure what I'm doing wrong here and how to repair it.

PS. I'm using Ubuntu as my OS.

2
Pheew, it seems like I did it. While this tutorial - mono-project.com/docs/database-access/providers/sqlite - is totally misleading and does not bring the desired result. The key ingredient is to install the right dll. Mono.Data.SqliteClient.dll - is not the right one, at least in my case it produces errors. And the right library is Mono.Data.Sqlite.dllJacobian

2 Answers

1
votes

It appears that Mono.Data.SqliteClient can not find the native SQLite binaries:

Prerequisites If you do not have SQLite, download it. There are binaries for Windows and Linux. You can put the .dll or .so along side your application binaries, or in a system-wide library path.

Ref: http://www.mono-project.com/docs/database-access/providers/sqlite/

To obtain pre-compiled native binaries (or source) for your platform:

Also if you have the SQLite native shared libraries installed, are they available via dlopen? If not, you can assign the LD_LIBRARY_PATH env. var so Mono can find them at runtime.

Linux Shared Library Search Path From the dlopen(3) man page, the necessary shared libraries needed by the program are searched for in the following order:

A colon-separated list of directories in the user’s LD_LIBRARY_PATH environment variable. This is a frequently-used way to allow native shared libraries to be found by a CLI program. The list of libraries cached in /etc/ld.so.cache. /etc/ld.so.cache is created by editing /etc/ld.so.conf and running ldconfig(8). Editing /etc/ld.so.conf is the preferred way to search additional directories, as opposed to using LD_LIBRARY_PATH, as this is more secure (it’s more difficult to get a trojan library into /etc/ld.so.cache than it is to insert it into LD_LIBRARY_PATH). /lib, followed by /usr/lib.

Ubuntu Notes:

$ sudo apt-get install sqlite
$ ls -1  /usr/lib/libsqlite*
/usr/lib/libsqlite.so.0
/usr/lib/libsqlite.so.0.8.6
$ export LD_LIBRARY_PATH=/usr/lib:$LD_LIBRARY_PATH
$ mono ./Test.exe
0
votes

I solve the problem in my Mac in this way. Right Click in Mono.Data.Sqlite on References and click in Local Copy. This make mono copy dll to debug folder and your application will find the library.
OBS: Sorry for my bad english.