4

After converting to Visual Studio 2010 with ReSharper5 some of my unit tests started failing. More specifically this applies to all unit tests that use NHibernate with SQLite. The problem seem to be related to SQLite somehow. The unit tests that does not involve NHibernate and SQLite are still running fine.

The exception is as follows:

NHibernate.HibernateException : Could not create the driver from NHibernate.Driver.SQLite20Driver, NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4.
  ----> System.Reflection.TargetInvocationException : Exception has been thrown by the 
        target of an invocation.
  ----> NHibernate.HibernateException : The IDbCommand and IDbConnection implementation 
        in the assembly System.Data.SQLite could not be found. Ensure that the assembly
        System.Data.SQLite 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.
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.

The exception is the NullReferenceException on TearDown when cleaning up NHibernate objects that wasn't successfully created, but the problem seem to be related to SQLite somehow.

I run my unit tests through ReSharper, but I get the same exception when running them directly through the NUnit.exe application. However, running them through the x86 variant (NUnit-x86.exe) all tests run fine. Can it be related to some mixing of 64bit and 32bit dlls? It still runs fine through VS2008 + ReSharper4.5.

Note that the target framework of my projects still is .NET3.5.

Anyone seen this problem before?

stiank81
  • 25,418
  • 43
  • 131
  • 202
  • I've been having issues too, but switching to x64 is giving me a loaderException. Are you using v.1.0.66.0? Did you change the build platform target to x64? – Berryl Apr 22 '10 at 16:56
  • v.1.0.66.0 of what? SQLite? I did not change build platform target - this is still set to default. I guess this means targeting the current platform, which is x64.. – stiank81 Apr 22 '10 at 18:37

4 Answers4

6

There seems to be a mixup between 64bit and 32bit dlls somehow. Switching to use the x64 variant of SQLite.dll fixes the problem. I'm not sure why VS2008 doesn't give this problem though.

stiank81
  • 25,418
  • 43
  • 131
  • 202
  • I had a similar problem in VS2008. Forcing the test project to compile as x86 instead of "Any CPU" and using the 32bit dll solved this for me. In configuration manager I had to add an x86 platform for the my test project, copying settings from the "Any CPU" platform. – w00ngy Jun 23 '14 at 14:08
3

I got the same error, I was sure that it was due to .NET 4.0 and VS 2010, but when I upgraded to Resharper 5 at work (on VS 2008), I got the same error.

I think this is caused by Resharper 5 test runner. When I used TestDriven.NET they all ran successfully.

I hope JetBrains will release a fix soon. According to what I saw on the forums, they are aware of the problem, so it should not take too long to have a fix.

While this is fixed, I will use TestDriven.NET to run my tests. But I will miss the great Resharper UI ;)

Charles Ouellet
  • 6,338
  • 3
  • 41
  • 57
  • Thanx for the feedback! Yeah - let's hope they fix it! Can't live without ReSharper :) – stiank81 Apr 22 '10 at 12:26
  • I'm getting this error on VS2008 with Resharper 5 when running the Machine.Specifications command line executable, but not through VS2008. – Derek Greer Jun 12 '10 at 23:07
2

Did you look at your compile settings in Visual Studio 2010?

For hiding their inability to get their newest debugger running in 64bit Microsoft decided to switch the default compilation for .Net applications from ANY_CPU to 32bit x86.

That could create your problems.

Foxfire
  • 5,675
  • 21
  • 29
  • Hmm - I didn't know that. I didn't change this, and it still says ANY_CPU. But starting a new project it says x86 by default. So it should be the same - but you're saying they have problems with x64?! If so *that* could explain a few things.. Maybe I'm better of switching to x86 builds? – stiank81 Apr 23 '10 at 12:40
  • Visual Studio has problems with x64 (exactly: the new debugger isn't 64-bit compatible). So for the application itself there should be no problems. – Foxfire Apr 23 '10 at 12:43
  • I see. Well - I seemed to have mixed myself into some x86 x64 incompatibility issues of some kind, so I think I'll try to change everything to x86 anyway to see if this helps.. – stiank81 Apr 23 '10 at 12:47
0

Could not create the driver from NHibernate.Driver.SQLite20Driver, NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4

Solution:

testsettings: choose hosts choose run tests in 64 bit process on 64 bit machine

hoping I could help.

merry coding