【发布时间】:2011-08-13 15:04:56
【问题描述】:
我正在使用标准 fluent nhibernate 下载中的所有 dll,以及标准 sqlite dll。
它只有在我将目标框架切换到 3.5 时才有效——在这种情况下,system.data 的引用切换到版本 2。——所以这个 dll 可能是原因。
我很惊讶流畅的 nhibernate 似乎不能立即工作。
如果有人能告诉我如何让 .net 4 控制台应用程序使用 .net 3.5 system.data dll(版本 2.),那可能会解决它。或者,如果某个地方有一个秘密的流利的 nhibernate 下载可以工作......
编辑:好的,这里有一些错误信息.......
编辑:已解决!使用此 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 ---
【问题讨论】:
-
您应该发布您看到的错误并确保您没有。 NET 4.0 客户端配置文件已选择。
-
"System.IO.FileLoadException: 混合模式程序集是针对运行时版本 'v2.0.50727' 构建的,如果没有其他配置信息,则无法在 4.0 运行时中加载。"似乎是你的问题。 stackoverflow.com/questions/2455654/… 是一个可能的解决方案。
-
好的,谢谢,我用这个 app.config 文件修复了它:
但仍然是一场噩梦。 -
确实,我想我可能会错过 SQLite,直到它更新为 4.0。我一直在使用 SQLCE 进行测试,它似乎工作得很好。
-
我仍然不知道 sqlite 是问题所在。我尝试了这个版本,即 .net 4.0:system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki ...它仍然无法正常工作(没有 ap.config 更改)。另一方面,nhibernate 和 fluent nhibernate dll 是针对 .net 2.0 构建的。
标签: .net nhibernate fluent system.data