【发布时间】:2011-09-16 21:08:29
【问题描述】:
去年,我在一个 VS2008 项目中非常成功地使用了 SubSonic 3 和 SQLite,并且对结果非常满意。就在最近,我尝试在 VS2010 项目中设置 SubSonic 3 和 SQLite,但在尝试实例化新的 SimpleRepository 时遇到了内部异常:
类型初始化器 'System.Data.SQLite.SQLiteFactory' 抛出异常
为了确保我没有发疯,我在 VS2008 中尝试了完全相同的代码和 app.config 文件,没有问题。奇怪!
目前,我正在使用 SubSonic 3.0.0.4 和 x64 版本的 System.Data.SQLite 1.0.73.0 (3.7.6.3)(尽管我也尝试了 32 位版本。)我添加了两个 DLL 作为参考并将“复制本地”设置为 TRUE。
我的 App.Config 看起来像:
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="myDatabase" connectionString="Data Source=C:\DB\mydatabase.db3" providerName="System.Data.SQLite"/>
</connectionStrings>
我的代码看起来像:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SubSonic.Repository;
namespace SubSonicSqliteTestConsole
{
class Program
{
static void Main(string[] args)
{
var repo = new SimpleRepository("myDatabase", SimpleRepositoryOptions.RunMigrations);
}
}
}
有什么想法吗?
【问题讨论】:
标签: sqlite subsonic subsonic3 system.data.sqlite