简体   繁体   English

调用SQLite在C#/ MonoDevelop中工作,但是当程序从命令行运行时崩溃

[英]Calls to SQLite work in C#/MonoDevelop but crash when program run from command line

Developing on MonoDevelop 3.0.5 and Mono 2.10.9 with SQLite 4.0 on Windows 7. Using C# and Mono is set for my active runtime. 在Windows 7上使用SQLite 4.0在MonoDevelop 3.0.5和Mono 2.10.9上进行开发。为我的活动运行时设置了使用C#和Mono。 Target framework is Mono/.NET 4.0. 目标框架是Mono / .NET 4.0。

My schema script loads fine into SQLite and I can access it from the sqlite3.exe/sqlite3.dll at the command line with no problems. 我的架构脚本可以很好地加载到SQLite中,并且可以从命令行从sqlite3.exe / sqlite3.dll对其进行访问,而不会出现问题。 I can connect to the database and perform select/update/insert and call functions such as count and last_insert_row_id from my C# code when I execute the code from within the MonoDevelop IDE (both run and debug work fine). 当我从MonoDevelop IDE中执行代码时,我可以连接到数据库并执行选择/更新/插入和从C#代码中调用计数和last_insert_row_id之类的功能(运行和调试工作都很好)。

When I try to execute the code from the command line and call myprogram.exe, the program crashes at the first database call. 当我尝试从命令行执行代码并调用myprogram.exe时,程序在第一次数据库调用时崩溃。 Significant data from the exception appears to be: 来自异常的重要数据似乎是:

System.IO.FileNotFoundException: Could not load file or assembly 'Mono.Data.Sqlite, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' or one of its dependencies. System.IO.FileNotFoundException:无法加载文件或程序集'Mono.Data.Sqlite,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 0738eb9f132ed756'或其依赖项之一。 The system cannot find the file specified. 该系统找不到指定的文件。 File name: 'Mono.Data.Sqlite, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' 文件名:'Mono.Data.Sqlite,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 0738eb9f132ed756'

The database and sqlite3.dll are in the same directory as myprogram.exe. 数据库和sqlite3.dll与myprogram.exe位于同一目录中。 This appears to be a system configuration issue which is not my forte. 这似乎是系统配置问题,这不是我的专长。 Hopefully it is obvious to someone wat I failed to configure on my development machine. 希望对我在开发机器上配置失败的人显而易见。

If you are running Windows 7 x64, please pay attention to bitness. 如果您运行的是Windows 7 x64,请注意位数。

When running in MonoDevelop (32 bit), your application (compiled as Any CPU) will be launched as 32 bit process. 在MonoDevelop(32位)中运行时,您的应用程序(编译为Any CPU)将以32位进程启动。 So when you said it runs fine, which means in 32 bit mode it runs fine. 因此,当您说运行正常时,即在32位模式下运行正常。

At command prompt (cmd.exe, 64 bit by default), your application will automatically run under 64 bit mode. 在命令提示符下(cmd.exe,默认为64位),您的应用程序将自动在64位模式下运行。 If it fails in that case, it means you will have to use 64 bit SQLite stuffs (both 64 bit sqlite3.dll and the 64 bit ADO.NET provider assembly). 如果在这种情况下失败,则意味着您将必须使用64位SQLite东西(64位sqlite3.dll和64位ADO.NET提供程序程序集)。 This should be clearly stated somewhere else on SQLite web site or the ADO.NET provider assembly documentation. 这应该在SQLite网站或ADO.NET提供程序程序集文档中的其他地方明确说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM