2

我正在使用标准 fluent nhibernate 下载中的所有 dll,以及标准 sqlite dll。

它仅在我将目标框架切换到 3.5 时才有效——在这种情况下,system.data 的引用切换到版本 2。——所以这个 dll 可能是原因。

我很惊讶流畅的 nhibernate 似乎不能立即工作。

如果有人能告诉我如何让 .net 4 控制台应用程序使用 .net 3.5 system.data dll(版本 2.),那可能会解决它。或者,如果某个地方有一个秘密的流畅的休眠下载可以工作......

编辑:好的,这里有一些错误信息.......


编辑:已解决!使用此 app.config 文件:

<?xml version="1.0"?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true"><supportedRuntime version="v4.0"/>
  </startup>
</configuration>

Unhandled Exception: FluentNHibernate.Cfg.FluentConfigurationException: An inval
id or incomplete configuration was used while creating a SessionFactory. Check P
otentialReasons collection, and InnerException for more detail.

 ---> FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplet
e configuration was used while creating a SessionFactory. Check PotentialReasons
 collection, and InnerException for more detail.

 ---> NHibernate.HibernateException: Could not create the driver from NHibernate
.Driver.SQLite20Driver, NHibernate, Version=3.1.0.4000, Culture=neutral, PublicK
eyToken=aa95f207798dfdb4. ---> System.Reflection.TargetInvocationException: Exce
ption has been thrown by the target of an invocation. ---> System.IO.FileLoadExc
eption: Mixed mode assembly is built against version 'v2.0.50727' of the runtime
 and cannot be loaded in the 4.0 runtime without additional configuration inform
ation.
   at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError,
Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, Bool
ean loadTypeFromPartialName, ObjectHandleOnStack type)
   at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError,
Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, Boolean l
oadTypeFromPartialName)
   at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean
ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
   at System.Type.GetType(String typeName)
   at System.Data.Common.DbProviderFactories.GetFactory(DataRow providerRow)
   at System.Data.Common.DbProviderFactories.GetFactory(String providerInvariant
Name)
   at NHibernate.Driver.ReflectionBasedDriver..ctor(String providerInvariantName
, String driverAssemblyName, String connectionTypeName, String commandTypeName)
in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Driver\ReflectionBasedDriver.cs:lin
e 49
   at NHibernate.Driver.SQLite20Driver..ctor() in d:\CSharp\NH\NH\nhibernate\src
\NHibernate\Driver\SQLite20Driver.cs:line 28
   --- End of inner exception stack trace ---
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOn
ly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Bo
olean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipChec
kThis, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean s
kipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at NHibernate.Bytecode.ActivatorObjectsFactory.CreateInstance(Type type) in d
:\CSharp\NH\NH\nhibernate\src\NHibernate\Bytecode\ActivatorObjectsFactory.cs:lin
e 9
   at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 set
tings) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Connection\ConnectionProvide
r.cs:line 98
   --- End of inner exception stack trace ---
   at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 set
tings) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Connection\ConnectionProvide
r.cs:line 113
   at NHibernate.Connection.ConnectionProvider.Configure(IDictionary`2 settings)
 in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Connection\ConnectionProvider.cs:l
ine 64
   at NHibernate.Connection.ConnectionProviderFactory.NewConnectionProvider(IDic
tionary`2 settings) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Connection\Conn
ectionProviderFactory.cs:line 50
   at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Action`1 scriptAction, Boolea
n export, Boolean justDrop) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Tool\hb
m2ddl\SchemaExport.cs:line 330
   at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Boolean script, Boolean expor
t, Boolean justDrop) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Tool\hbm2ddl\S
chemaExport.cs:line 290
   at NHibernate.Tool.hbm2ddl.SchemaExport.Create(Boolean script, Boolean export
) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Tool\hbm2ddl\SchemaExport.cs:line
 105
   at FluentNHibernateTest4.Program.BuildSchema(Configuration config) in C:\User
s\anna\Documents\Visual Studio 2010\Projects\TestFluentNHibernate\FluentNHiberna
teTest4\Program.cs:line 97
   at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() in d:\Builds
\FluentNH-v1.x-nh3\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 254
   --- End of inner exception stack trace ---
   at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() in d:\Builds
\FluentNH-v1.x-nh3\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 261
   at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in d:\Build
s\FluentNH-v1.x-nh3\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 227
   --- End of inner exception stack trace ---
4

2 回答 2

3

在 Visual Studio 2010 项目中引用 Fluent nHibernate 的最简单方法可能是安装 NuGet 扩展 ( http://nuget.codeplex.com/ ) 并使用它来添加 Fluent nHibernate 及其对项目的依赖项。

也可以使用此方法将 SQLite 添加到您的项目中(目前有两个可用的包 SQLite(仅限 32 位)和 SQLitex64(32 位 + 64 位)。SQLite NuGet 包还将添加解决您收到的异常所需的附加配置:

NHibernate.HibernateException: Could not create the driver from NHibernate
.Driver.SQLite20Driver, NHibernate, Version=3.1.0.4000, Culture=neutral, PublicK
eyToken=aa95f207798dfdb4. ---> System.Reflection.TargetInvocationException: Exce
ption has been thrown by the target of an invocation. ---> System.IO.FileLoadExc
eption: Mixed mode assembly is built against version 'v2.0.50727' of the runtime
 and cannot be loaded in the 4.0 runtime without additional configuration inform
ation.

此问题也处理了此异常:在 .NET 4.0 项目中引用 .NET 2.0 混合模式程序集需要哪些“附加配置”?

于 2011-08-13T15:10:27.543 回答
0

我遇到了同样的错误,我根据在 Stack 上找到的提示执行了每项任务。但问题仍然存在。我的情况是,所有的东西都不在主项目中,我为第二个引用项目(充当数据层)执行的每个 Nuget 安装。最后,在解决方案编译后,构建文件夹中没有程序集 System.Data.SQLite(未复制)。

我也通过在主项目下运行 System.Data.SQLite 的 Nuget 安装解决了这个问题。

于 2013-08-05T08:42:46.157 回答