8

I have problem with this exception:

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.

I tried everything. I googled a lot.

System.Data.SqlServerCe.dll is in debug directory. Is local referenced, is not i GAC. I have copy local set true. In debug directory is all other needed sql*.dll. I tried x86 compilation but nothig.

This is my nhibernate config:

<?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 version 3.0 beta 1, SqlServerCe version 3.5 SP1

My idea: Nhibernate still look in GAC, becouse a had installed SqlServerCe, after uninstall the problem starts. How can I say to NHibernate: "please look take this dll?":)

0

4 Answers 4

11

You (or the NHibernate dll) are referencing a different version of the System.Data.SqlServerCe dll in the project than what it is expecting. For instance, NHibernate may be referencing the .NET 3.5 version of the dll, but you have the .NET 4.0 version of the dll in the GAC or local bin directory. You can instruct the .NET framework to use a specific AssemblyBinding to correct the problem. Type the following in your config file to fix it.

    <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> 

Sign up to request clarification or add additional context in comments.

1 Comment

Did not need this on the newest version of nHibernate, but could not replace an older version and this fixed my issue.
0

Try to load the assembly with Assembly.LoadFile with the complete path to the DLL before NHibernate requests it.

NHibernate will load the assembly using Assembly.Load("NHibernate.Driver.SqlServerCeDriver") which will probably look in the GAC. If you force to load it from a file, the Assembly.Load will notice it's already loaded and pick the one you loaded.

6 Comments

I am getting this error: System.IO.FileLoadException : Could not load file or assembly 'System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91 or one of its dependencies. The system cannot find the specified file. I tried to load depended dll but i get this error, when I try to load sqlceca35.dll : System.BadImageFormatException: The module should contain assembly manifest. (Exception to the HRESULT: 0x80131018)
Maybe this can help, but i dont know where to write it.<qualifyAssembly partialName="System.Data.SqlServerCe" fullName="System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91 "/ >
It's correct that sqlceca35.dll gives that error. That shouldn't be loaded using Assembly.Load and is used with p/invoke. But, concerning the first error, can you please show the Assembly.LoadFile() line you tried this with? Maybe that helps.
Assembly.LoadFile(@"C:\Users\Simon\Workspace\C#\Works\MyProject\ branches\MyProject\MyProject.DatabaseLayer\bin\Debug\System.Data.SqlServerCe.dll");
Sorry, I have no clue. Two suggestions though: firstly, the exception may contain details on what went wrong. Try to inspect all the details of the exception to see whether that helps. If all else fails, try ProcMon technet.microsoft.com/en-us/sysinternals/bb896645.aspx and inspect the logs.
|
0

You can also set the use specific version flag to false on the properties in VS for that reference and set copy local to true

Comments

-1

I switched to sqllite. Thats work. Maybe consider to change byte code. I used spring byte code, maybe castle is better....

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.