我对这个异常有问题:
Hibernate.HibernateException : Could not create the driver from Hibernate.Driver.SqlServerCeDriver.
----> System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
----> NHibernate.HibernateException : The IDbCommand and IDbConnection implementation in the ssembly System.Data.SqlServerCe could not be found. Ensure that the assembly System.Data.SqlServerCe is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use <qualifyAssembly/> element in the application configuration file to specify the full name of the assembly.
我什么都试过了。我用谷歌搜索了很多。
System.Data.SqlServerCe.dll在调试目录中。是本地引用的,不是I GAC。我将copy local设置为true。在debug目录中是所有其他所需的sql*.dll。我尝试过x86编译,但没有。
这是我的nhibernate配置:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name='proxyfactory.factory_class'>NHibernate.ByteCode.Spring.ProxyFactoryFactory, NHibernate.ByteCode.Spring</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSqlCeDialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlServerCeDriver</property>
<property name="show_sql">true</property>
<!-- mapping files -->
</session-factory>
</hibernate-configuration>
NHibernate 3.0测试版1、SqlServerCe 3.5版SP1
我的想法是: Nhibernate还在GAC中找,因为已经安装了SqlServerCe,卸载后问题就开始了。我如何对NHibernate说:“请看,把这个动态链接库拿走?”:)
发布于 2011-10-29 15:42:45
您(或NHibernate dll)在项目中引用的System.Data.SqlServerCe dll版本与其预期的版本不同。例如,NHibernate可能引用了.NET 3.5版本的dll,但是在GAC或本地bin目录中有.NET 4.0版本的dll。您可以指示.NET框架使用特定的AssemblyBinding来纠正该问题。在您的配置文件中键入以下内容以修复它。
<runtime>
<assemblyBinding
xmlns="urn:schemas-microsoft-com:asm.v1"><qualifyAssembly
partialName="System.Data.SqlServerCe" fullName="System.Data.SqlServerCe,
Version=3.5.1.0, Culture=neutral,
PublicKeyToken=89845dcd8080cc91"/>
</assemblyBinding>
</runtime>
发布于 2010-11-07 21:26:56
在NHibernate请求程序集之前,尝试使用包含DLL完整路径的Assembly.LoadFile
加载该程序集。
NHibernate将使用Assembly.Load("NHibernate.Driver.SqlServerCeDriver")
加载程序集,这可能会在GAC中查找。如果您强制从文件加载它,Assembly.Load
将注意到它已经加载,并选择您加载的文件。
发布于 2012-09-13 17:47:26
您还可以在VS中的属性上将该引用的使用特定版本标志设置为false,并将copy local设置为true
https://stackoverflow.com/questions/4117830
复制相似问题